env variables again

What is the difference between ${variable} and $variable when used in a script?

Just like that? Nothing. But try this snippet:

variable='Test'
echo "${variable}1"
echo "$variable1"

No difference. The right syntax is ${var} but $var is shortcut when it's unambiguous (and it often is).

f=somefile
mv "$f" "$f".bak # no needed
mv "$f" "${f}_bak" # needed
1 Like