-   Linux - Newbie (
-   -   whats the use of '$' in Linux Command (

SkM007 10-09-2011 05:40 PM

whats the use of '$' in Linux Command

I got really silly question... whats the use of '$' in Linux Command... i have seen many commands with $ sign, specially in scripting... can someone please explain me (in layman's language)... also whats the exact use of echo command... this combo echo & $ is used a lot in scripting...

Thanks in Advance!!!

corp769 10-09-2011 05:42 PM

In layman's terms, in reference for scripts, the $ symbol designates variables. Observe the following:

read -p "What is your name? " name1
echo "Hello, $name1"

Also, read here -



grail 10-09-2011 06:53 PM

You could also do a man on bash and search for ${parameter} has information on what $ does and you can also search for echo in there or do help echo on the command line.

David the H. 10-11-2011 09:12 AM

To be slightly more precise, the $ is used to designate parameter expansion. When you want to use the contents of a variable or the results of a command substitution in your script, you add the $ to the front of it.

Variable names themselves can only consist of letters, numbers, and underscores. This is different from languages like perl or php, where the variable names themselves start with dollar signs or other characters.


# example of variable expansion:
> foo="hello world"  #set the variable named "foo" to the value of "hello world"
> echo "$foo"        # expand and print the contents of foo
hello world

# example of command substitution "$(..)":
> file -i foo.txt        # this is the output of the file command
foo.txt: text/plain; charset=us-ascii

> foo="$( file foo.txt | sed 's/.*=//' )"  #set variable "foo" to the output of file,
                                          #filtered through sed to strip off all
                                            #but the last section.
> echo "$foo"

If you really want to learn about shell scripting, read through the BashGuide. It covers all the basic concepts:

SkM007 10-30-2011 01:23 PM

Thanks to all!!!! & thanks for those links, its quite informative...

All times are GMT -5. The time now is 09:59 PM.