Shell script command line arguments

Hello All,
i am known to the limitation of different shells while passing more than 9 command line arguments
i just tried the example below
i do see my current shell is tcsh

echo $SHELL
/bin/tcsh

so if i make my script executable and run it

output is

%ingrx025:/home/grvobad2/shell/tes/deepak/shell >ls -l command_arg.sh
-rwxrwxr-x   1 grvobad2 grcdc        314 Dec 20 14:19 command_arg.sh
%ingrx025:/home/grvobad2/shell/tes/deepak/shell >./command_arg.sh 11 12 13 14 15 16 17 18 19 20 21
first arg passed is 11
2nd arg passed is 12
3rd arg passed is 13
4th arg passed is 14
5th arg passed is 15
6th arg passed is 16
7th arg passed is 17
8th arg passed is 18
9th arg passed is 19
10th arg passed is 110-------  as expected wrong output
11th arg passed is 111---------as expected wrong output

But if i run ,

%ingrx025:/home/grvobad2/shell/tes/deepak/shell >tcsh command_arg.sh 11 12 13 14 15 16 17 18 19 20 21
first arg passed is 11
2nd arg passed is 12
3rd arg passed is 13
4th arg passed is 14
5th arg passed is 15
6th arg passed is 16
7th arg passed is 17
8th arg passed is 18
9th arg passed is 19
10th arg passed is 20
11th arg passed is 21
 

i do get correct output

i am running the script in a same shell but way is different and i get differnet output

Script is :

cat command_arg.sh
echo "first arg passed is $1"
echo "2nd arg passed is $2"
echo "3rd arg passed is $3"
echo "4th arg passed is $4"
echo "5th arg passed is $5"
echo "6th arg passed is $6"
echo "7th arg passed is $7"
echo "8th arg passed is $8"
echo "9th arg passed is $9"
echo "10th arg passed is $10"
echo "11th arg passed is $11"

Please let me know why is it happening?

For getting the arguments with 2 digits, You should give as below,

echo "10th arg passed is ${10}"
echo "11th arg passed is ${11}"

thanks for answer i am known to this and yes, it varies for different shells

i have a doubt in

though my present shell is /bin/tcsh and if i run a script with

./script_name

the output is different than

tcsh script_name

?

What system you're running the test on? I'm able to reproduce that behavior on Cygwin, but not on Linux (Ubuntu 10.10).

it is on solaris

uname -a
SunOS ingrx025 5.10 Generic_118822-25 sun4u sparc SUNW,Sun-Fire-V240

I believe I understand why this is happening, it's should be specific to [t]csh and I suppose documented somewhere :slight_smile:
On some (or all?) systems (Solaris included) when you invoke a script with no shebang as ./script_name from within [t]csh the script is executed by a predefined interpreter (/usr/bin/sh on Solaris):

> uname -sr ; echo $version
SunOS 5.8
tcsh 6.11.00 (Astron) 2001-09-02 (sparc-sun-solaris) options 8b,nls,dl,al,rh,color
> cat command_arg.sh
echo '----->' `ps -p$$ -oargs=`
echo "first arg passed is $1"
echo "2nd arg passed is $2"
echo "3rd arg passed is $3"
echo "4th arg passed is $4"
echo "5th arg passed is $5"
echo "6th arg passed is $6"
echo "7th arg passed is $7"
echo "8th arg passed is $8"
echo "9th arg passed is $9"
echo "10th arg passed is $10"
echo "11th arg passed is $11"
> ./command_arg.sh 11 12 13 14 15 16 17 18 19 20 21
-----> /bin/sh ./command_arg.sh 11 12 13 14 15 16 17 18 19 20 21
first arg passed is 11
2nd arg passed is 12
3rd arg passed is 13
4th arg passed is 14
5th arg passed is 15
6th arg passed is 16
7th arg passed is 17
8th arg passed is 18
9th arg passed is 19
10th arg passed is 110
11th arg passed is 111

So given the following script:

$ cat s
ps -p$$ -oargs=

We have:

$ bash -c './s'
bash -c ./s
$ ksh -c './s'
ksh -c ./s
$ tcsh -c './s'
/bin/sh ./s
$ csh -c './s'
/bin/sh ./s

Tested on Solaris e Linux.

thanks it seems the same as u explained though yet to understand your tracing techniques :slight_smile: