LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-09-2011, 05:40 PM   #1
SkM007
LQ Newbie
 
Registered: Jun 2011
Distribution: Oracle, BackTrack
Posts: 28

Rep: Reputation: Disabled
whats the use of '$' in Linux Command


Hiii,

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!!!

Last edited by SkM007; 10-09-2011 at 05:42 PM. Reason: modification
 
Old 10-09-2011, 05:42 PM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
In layman's terms, in reference for scripts, the $ symbol designates variables. Observe the following:
Code:
#!/bin/bash
read -p "What is your name? " name1
echo "Hello, $name1"
Also, read here - http://tldp.org/LDP/Bash-Beginners-G...ect_03_02.html

Cheers,

Josh
 
1 members found this post helpful.
Old 10-09-2011, 06:53 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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.
 
1 members found this post helpful.
Old 10-11-2011, 09:12 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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.

Code:
# 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"
us-ascii
If you really want to learn about shell scripting, read through the BashGuide. It covers all the basic concepts:

http://mywiki.wooledge.org/BashGuide
 
Old 10-30-2011, 01:23 PM   #5
SkM007
LQ Newbie
 
Registered: Jun 2011
Distribution: Oracle, BackTrack
Posts: 28

Original Poster
Rep: Reputation: Disabled
Smile

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


Reply

Tags
command



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
whats the first command? matthewa Linux From Scratch 4 04-04-2005 02:45 PM
MEncoder: Whats wrong with this command? flamesrock Linux - Software 1 07-15-2004 07:03 PM
whats the command to start firefox? Wiggy Linux - Software 12 04-28-2004 07:29 PM
whats the open command? zexter Linux - General 17 11-02-2003 12:57 AM
whats the command for this. dkc_ace Linux - General 1 12-20-2002 09:55 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration