$i


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting $i
# 1  
Old 01-11-2008
Question $i

Hi,

I tryed to do this part of script:

while (( i <= $# ))
do
echo $i
echo '$'$i

case $i in #or $$i
"-p")
echo -p
((i += 1))
if test $i == "-d"
then
echo Error
exit 1
fi
((i -= 1));;

"-d")
;;

"-min")
;;

"-max")
;;
esac


((i += 1)) #C style
done

I write this script thinking that $i or $$i will be interpreted like a $1, $2,.. the parameters

But this isn't what the script do.

How can I edit it to make what I want?
# 2  
Old 01-11-2008
try this.

Code:
echo "\$$i"

# 3  
Old 01-12-2008
Quote:
Originally Posted by frank_rizzo
try this.

Code:
echo "\$$i"

The echo WORKS.

But the CASE don't work with "\$$i".

I want the CASE compare the arguments ( $1, $2, ...) with what they can contain.

for example in C I would write:

for(i=1; i<argc; i++)
{
if(strcmp(argv[i], "-f")==0)
opz_f=1;
else if(strcmp(argv[i], "-w")==0)
{
opz_w=1;
w=i;
}
}

How do you implement argv[i] == "string" in BASH SCRIPT?
# 4  
Old 01-12-2008
There is no need to reinvent the wheel.
Code:
man getopts

but if you must. try this

Code:
myvar=\$$i
case $myvar in
...

note: please use the [CODE] tags when posting code. It's very hard to read without them.

Last edited by frank_rizzo; 01-12-2008 at 10:58 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question