I do a echo $1, it prints out what is the default login shell used.

But for echo $2 onwards, all I get is a newline. Why is that?

link|improve this question

feedback

2 Answers

up vote 10 down vote accepted

$1 (or $2,$3 ...) is supposed to be the arguments given to some script.

Here's an example script:

#!/bin/bash

echo "\$1 is now $1"
echo "\$2 is now $2"
echo "\$3 is now $3"

And the example output

jaba@lappy:/tmp$ ./example.sh 
$1 is now 
$2 is now 
$3 is now 
jaba@lappy:/tmp$ ./example.sh 1 2 3
$1 is now 1
$2 is now 2
$3 is now 3
link|improve this answer
And $0 is the name of the scipt being executed, analogous to argv. – honk Jul 30 '10 at 9:29
feedback

In your case $1 prints default login shell used because this argument was passed to script that runs your login shell. But if you'll write and run your own script in current session, $1, $2, ... will be parameters that you send to your script.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.