Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

howto get parameters

Status
Not open for further replies.

rvarman

IS-IT--Management
Apr 24, 2003
91
FR
i execute a file passing 3 or 4 parameters.
I'm unable to get the parameters inside a loop.

#test.sh
n=1
while ((n <= $#))
do
echo &quot;parm=&quot; $n
file=file$n.txt
((n=n + 1))
done

when i execute test.sh a b c
i get
parm= 1
parm=2
parm=3

whereas i want to get
parm=a
parm=b
parm=c


Your suggestions please

 
Hi,
to do what you want type
echo &quot;parm=&quot;$(eval echo \$$n)
very 'easy'
Regards Boris
 
Try this:

n=1
while ((n <= $#))
do
echo &quot;parm=&quot; $n
echo $1 $2 $3
file=file$n.txt
((n=n + 1))
done

result:

# test3 a b c
parm= 1
a b c
parm= 2
a b c
parm= 3
a b c
#

$1 is the first parameter
$2 the second and so on
 
Boris' soln works fine.
Merci boris.

you know howto print spaces in the variables?

a=&quot;abcd&quot;
b=&quot; &quot; #4 spaces
c=&quot;efgh&quot;

echo $a$b$c gives &quot;abcd efgh&quot;
wheras i want, &quot;abcd efgh&quot;

regards ravi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top