bash: splitting up arg in loop

bash: splitting up arg in loop

Post by dea » Fri, 12 Apr 1996 04:00:00



                             Hi !

What I want to do is to split up an argument passed to a
bash-shellscript. I want to run the script like this:

<scriptname> arg1 arg2 arg3 <...>

With an *unknown* amount of arguments.
This is what my script looks like:

#!/bin/sh
# I want to echo all the parameters I pass this script. One after the other.

declare -i i=1
while [ $i -le $# ]
do
  echo <what shall I put here ?>
  i=i+1
done

echo $i counts from 1 to the number of arguments. How do I make it
echo the arguments one after the other ?

                        TNX Andreas

PS: Email would be appreciated.

-----------------------------------------------------------------------------

                                              Andreas Steffan

* win: command not found

------------------------------------------------------------------------------

 
 
 

bash: splitting up arg in loop

Post by E. A. Graham J » Fri, 12 Apr 1996 04:00:00



>What I want to do is to split up an argument passed to a
>bash-shellscript. I want to run the script like this:

><scriptname> arg1 arg2 arg3 <...>

>With an *unknown* amount of arguments.

Try this instead:

        NUMARG=$#
        until [ $[NUMARG] -le 0 ] ; do
                echo $1
                NUMARG=$[$[NUMARG]-1]
                if [ $[NUMARG] -gt 0 ] ; then shift ; fi
        done

The "shift" command "down-shifts" the arguments: $1 is now set to what
$2 was, $2 is now what $3 was, and the original $1 has dropped off the
face of the earth.

The "$[..]" means to evaluate numerically.

E. A. Graham, Jr.
Unemployed Computer Geek
(Remainder of .sig censored by the CDA provisions in the Telecomm
Bill...)

 
 
 

bash: splitting up arg in loop

Post by VA Bri » Sat, 13 Apr 1996 04:00:00


: What I want to do is to split up an argument passed to a
: bash-shellscript. I want to run the script like this:

: <scriptname> arg1 arg2 arg3 <...>

: With an *unknown* amount of arguments.
: This is what my script looks like:

: #!/bin/sh
: # I want to echo all the parameters I pass this script. One after the other.

: declare -i i=1
: while [ $i -le $# ]
: do
:   echo <what shall I put here ?>
:   i=i+1
: done

try


   do
      echo $ARGUMENT
   done

--

 
 
 

bash: splitting up arg in loop

Post by Andrew Snyd » Tue, 16 Apr 1996 04:00:00



>                         Hi !
>What I want to do is to split up an argument passed to a
>bash-shellscript. I want to run the script like this:
><scriptname> arg1 arg2 arg3 <...>
>With an *unknown* amount of arguments.
>This is what my script looks like:
>#!/bin/sh
># I want to echo all the parameters I pass this script. One after the other.
>declare -i i=1
>while [ $i -le $# ]
>do
>  echo <what shall I put here ?>
>  i=i+1
>done
>echo $i counts from 1 to the number of arguments. How do I make it
>echo the arguments one after the other ?
>                    TNX Andreas
>PS: Email would be appreciated.
>-----------------------------------------------------------------------------
>                                          Andreas Steffan

>* win: command not found
>------------------------------------------------------------------------------

You need a copy of "The Unix Programming Environmnet"


do
   echo $x
done
Andrew Snyder

char disclaimer[] = {'\0'}; /* I'm on cash net */

 
 
 

1. BASH BASH BASH BASH BASH BASH BASH BASH BASH BASH

Is there a proper fixed bash on any of the FTP sites out there?

I know there bash is on the usual sites but I don't know if they are
bugged or not :(

Regards,

Neil.

--


------------------------------------| Edinburgh, EH14 2DE, United Kingdom
**Domino: There`s nothing you can do when you`re the next in line: Domino**

2. Cannot join windows machines to samba domain with openldap backend

3. sh cmd-line arg splitting

4. g++ thread compiler switch?

5. How to split up a single string arg into separate arguments

6. add support for PC-9800 architecture (sound oss #1)

7. How to split up a single string arg in

8. Header file problem or dosemu problem?

9. Shape Ups,Men's Shape Ups,Men's Skechers Shape Ups - new styles!

10. invoking ld(1) with -z ld32=arg when arg takes a comma

11. Arg passing to alias in BASH