LinuxQuestions.org
Review your favorite Linux distribution.
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, 06: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 06:42 PM. Reason: modification
 
Old 10-09-2011, 06:42 PM   #2
corp769
Guru
 
Registered: Apr 2005
Posts: 5,814

Rep: Reputation: 1001Reputation: 1001Reputation: 1001Reputation: 1001Reputation: 1001Reputation: 1001Reputation: 1001Reputation: 1001
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, 07:53 PM   #3
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,692

Rep: Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987
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, 10:12 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950
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, 02: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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 03:45 PM
MEncoder: Whats wrong with this command? flamesrock Linux - Software 1 07-15-2004 08:03 PM
whats the command to start firefox? Wiggy Linux - Software 12 04-28-2004 08:29 PM
whats the open command? zexter Linux - General 17 11-02-2003 01:57 AM
whats the command for this. dkc_ace Linux - General 1 12-20-2002 10:55 PM


All times are GMT -5. The time now is 01:40 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration