Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

3 Answers 3

up vote 11 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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