****************************************
* LUG meet on 12 Jan. 2003 @ VJTI
****************************************

Hi,


You could use this too


#!/bin/bash
#
# e.g. sample.sh foo1 foo2 foo3
# then the following will happen : arg[0]=foo1, arg[1]=foo2 , arg[2]=foo3
#

count=0 # Counts the number of parameters

until [ -z "$1" ] # loop until all the parameters are usedup
  do
    arg[$count]=$1 # the $arg[] is like a normal array and
                   # $1 is the first argument to the script

    echo -en "Argument $count is $arg[$count]\n" # Debug Output


    count=$(($count+1))

    shift # shifts the argument number by one thus
          # now $1 is argument number two rather being argument one
  done





thanks
Ripunjay Bararia






-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Nikhil Joshi
Sent: Monday, December 16, 2002 9:59 PM
To: ilug
Subject: [ILUG-BOM] Bash script doubt


****************************************
* LUG meet on 12 Jan. 2003 @ VJTI
****************************************

Hi!

I'm trying to take command line args with the help of a bash script
But i'm not able to achieve it
Pls guide.

#!/bin/bash
# i want to detect command line options
# e.g. sample.sh -1 foo1 -2 foo2 -3 foo3
# then i want following : arg1=foo1, arg2=foo2 , arg3=foo3
# I tried following but arg1 takes the value $2, arg2 $3  and arg3 $3


count=0 # counter to track current command line arg

for cmd in $@
  do
     count=`expr $count + 1` # count = count + 1
     if `test $cmd = -1`
      then
        arg1=$`expr $count + 1`
        echo $arg1 # unfortunately it gives $2 and not foo1
     fi
  done






--
_______________________________________________

http://mm.ilug-bom.org.in/mailman/listinfo/linuxers


-- 
_______________________________________________

http://mm.ilug-bom.org.in/mailman/listinfo/linuxers



Reply via email to