Meaning of $ symbol in bash

Can someone please explain what the $ is used for in bash? Currently doing the following exercuse: https://www.codecademy.com/courses/learn-the-command-line/projects/attica.
And I am confused by step 11. It asks me to echo USER but it will not work unless I place the $ in front of user?

I have searched for answer and was told that it used to exit bash, which just confused me even more.

Look forward to find out this answer, as I am thinking it is quite simple.

Cheers.

James

It’s the basic form of expansion. You have a variable called USER but echo USER would just echo the text USER. With the $ character prepending that variable you replace part of your string with the text contained in the variable instead. The $ symbol is one of the special characters used that aren’t raw text (there are quite a lot in bash).

You can always check the bash docs if you want more info but the following page probably covers more than you need to know on parameter expansion (some of these are likely bash specific)-
https://wiki.bash-hackers.org/syntax/pe

2 Likes