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