On Mon, 16 Dec 2002, Nikhil Joshi wrote:
# 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
try this one, i tried with getopts, didnt impress me.
#!/bin/bash
i=0 # counter
while test $# -ne 0; do p=$1 # getting parameter value let i=i+1 if test $p = "-${i}"; then shift eval arg$i=$1 # argno=value fi shift done
echo "arg1=$arg1, arg2=$arg2"
regards sanjeev