bashdollar-sign

What is the $ in bash?


I've been using bash for about 3 mounth.
I'm understanding the language step by step but I have a question.
The real significate of $ in bash is the same of C?

I mean the $ not $1, $0, $# etc etc.
Only the $.


Solution

  • The $ is used to perform parameter expansion. For a variable named foo, the expression $foo expands to the value of the variable.

    $ foo=3
    $ echo "foo"
    foo
    $ echo "$foo"
    3
    

    $ is also used as the default/generic prompt, but there it is simply used as a distinctive character; it has no actual meaning, and could be replaced without causing any change in functionality.