Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 15 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
share|improve this answer
    
And $0 is the name of the scipt being executed, analogous to argv. – Benjamin Bannier Jul 30 '10 at 9:29

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.

share|improve this answer

$1 is the argument passed for shell script.

Suppose, you run

./myscript.sh hello 123 

then

$1 will be hello

$2 will be 123

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .