What's the difference between
temp=1? Why do I need the dollar sign?
#!/bin/bash temp=$1 cell=$((($temp-32)*5/9)) echo $cell
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
The dollar-sign triggers parameter expansion;
1 is the string
$1 is the first shell parameter.
[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.
$xyz points to the value of the variable
$2, ... are special cases where it points to the arguments passed from command line, if any.