Unable to print dynamic arguments in for loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unable to print dynamic arguments in for loop
# 1  
Old 03-16-2012
Question Unable to print dynamic arguments in for loop

Hi All,

I want to pass few dynamic arguments to shell script. The number of arguments differ each time I call the script.

I want to print the arguments using the for loop as below. But not working out.
Code:
for (( i=1; i<=$#; i++ ))
do
  echo $"($i)"
done

Code:
/bin/sh test.sh arg1 arg2 arg3

Any one please help.

Last edited by Franklin52; 03-16-2012 at 05:47 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 03-16-2012
Code:
for((i=1; i<=${#}; ++i)); do
     echo ${!i}
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to print python array in shell script loop.

I am unable to loop print a python string array in my unix shell script: ~/readarr.sh '{{ myarr }}' more readarr.sh echo "Parameter 1:"$1 MYARRAY= $1 IFS= MYARRAY=`python <<< "print ' '.join($MYARRAY)"` for a in "$MYARRAY"; do echo "Printing Array: $a" done Can you... (10 Replies)
Discussion started by: mohtashims
10 Replies

2. Shell Programming and Scripting

How to make dynamic variable names for use in while loop?

i=0 while do sizesfor0=`cat 16 | grep 'pickSize' -A 1 | grep '_sz' | cut -d'_' -f1` sizesfor0=${sizesfor0//id=\"lll/:} IFS=: array0=( $sizesfor0 ) echo ${array0} i=$(( $i + 1 )) done So, right now I have two variables in the while statement above sizesfor0 and array0 The... (1 Reply)
Discussion started by: phpchick
1 Replies

3. Shell Programming and Scripting

php file unable to run shell script with arguments

echo $result=exec("./permit.sh".$_FILES); pls suggest some other method to run shell script in php .:wall::mad: (0 Replies)
Discussion started by: upvan111
0 Replies

4. Shell Programming and Scripting

[C SHELL] How to pass dynamic number of arguments

I have a task. The scenario is like this. I have a operation program (OPR1) , whose function is to simply double the (single)value it receives as input. I have to write a script to operate the OPR1 and save its output in a file. Later, I have to modify the script so as to be able to operate ... (0 Replies)
Discussion started by: animesharma
0 Replies

5. UNIX for Dummies Questions & Answers

How to print arguments in reverse order?

Hey all, How do I make a script print its arguments in reverse order? Thanks (5 Replies)
Discussion started by: unclepickle1
5 Replies

6. Shell Programming and Scripting

Print arguments with the help of variable

Let's say I want to print the arguments $4 till $#, how can I do this? $# contains the number of arguments $@ contain all the arguments as string What i need is something like for i in $4_till_$#; do #do something with $i convert $i ~/$output done The first 3 arguments are used as options... (6 Replies)
Discussion started by: hakermania
6 Replies

7. Shell Programming and Scripting

dynamic index for array in while loop

Hi, I'm just trying to use a dynamic index for some array elements that I'm accessing within a loop. Specifically, I want to access an array at variable position $counter and then also at location $counter + 1 and $counter + 2 (the second and third array positions after it) but I keep getting... (0 Replies)
Discussion started by: weak_code-fu
0 Replies

8. Shell Programming and Scripting

Problem with dynamic variables outside the loop

Hi All, Shell is ksh I've given portion of the script here to explain the problem. It will accept 2 input parameters . in_file1=$1 in_file2=$2 outbound_dir=/home/outbound for i in 1 2 do eval file$i=$outbound_dir/\$in_file$i eval echo "filename is \$file$i" ... (4 Replies)
Discussion started by: kk17
4 Replies

9. Shell Programming and Scripting

How to print arguments along with spaces using awk

Hi All, file_1.txt contains aaa bbbb hhhh vvvvv mmmmm iiiii What i want is to search for the first coloumn of each line using awk.i.e as below: awk '/aaa/ {printf(<>)}' file_1.txt The print part (<>) should contain all the values(or coloumns ) in the particular line(here it... (8 Replies)
Discussion started by: jisha
8 Replies

10. Shell Programming and Scripting

Dynamic update loop query on Sybase database

Hello Guys, I'm new to Shell scripting, and i need someone to help me with this issue: I'm trying to do a dynamic update query on Sysbase database table using shell script. Lets say, the Update query is "update Table set id=X" , where X is dynamic value for the loop index. If the loop is... (10 Replies)
Discussion started by: Alaeddin
10 Replies
Login or Register to Ask a Question