Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

What's the difference between temp=$1 and temp=1? Why do I need the dollar sign?

For example:



echo $cell
share|improve this question

migrated from stackoverflow.com Feb 21 '12 at 16:52

This question came from our site for professional and enthusiast programmers.

mywiki.wooledge.org/BashGuide – jordanm Feb 20 '12 at 20:54

The dollar-sign triggers parameter expansion; 1 is the string "1", while $1 is the first shell parameter.

share|improve this answer

[In addition to what ruakh had already mentioned]

Your script attempts to convert a temperature value from Fahrenheit to Celsius scale. You could save your file with a name say, tocelsius.sh. Now, you can convert any given temperature (in Fahrenheit scale) by passing a value to your script:

bash tocelsius.sh 66

When you do so, your $1 would contain the value 66. Thus, you would get the corresponding output.

However, when you write temp=1, the variable temp will always take the fixed value 1. No argument passed to your script (as shown above) would be considered.

To conclude, $xyz points to the value of the variable xyz. $1, $2, ... are special cases where it points to the arguments passed from command line, if any.

share|improve this answer

Your Answer


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