Loop in shell script

Dear experts,

i am quite new to shell script please any one can help me in this regard

i would like write a script which takes input in the form

>.

/Test.sh a,10,b,20,c,30...
 in this way i can give input in any number which is not constant

in the end through loop i want to print a=10
b=20
c=30......

so on for any given input can you please explain me how to do this.

thanks in advance.

one simple way:

#  cat test.sh
#!/bin/sh
while [ $# -gt 0 ]
do
x=$1
y=$2
shift 2
echo $x"="$y
done

#  test.sh a 10 b 20 c 30
a=10
b=20
c=30

HTH - let me know if this makes sense - there are a number of ways of handling this sort of thing, and it can depend a little on exactly what you are wanting to do overall...but if you're trying to learn I think this should be a good start point...you can get "cleverer" when you understand the basics, but always learn to walk before running :wink:

Happy scripting..

:slight_smile:

Thank you for the reply,

but the input is not the one which i gave i will be given a comma separated

for ex: ./Test.sh a,10,b,20,c,30

after this the input has to be taken in the array and at last the o/p to be
a=10
b=20
c=30

my input is not ./Test.sh a 10 b 20 //no this is no my input

my input is ./Test.sh a,10,b,20...
i want to get the o/p from an array,

please help.

just set IFS=","

:D:D:D:D