LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 02-16-2012, 10:43 PM   #1
Knightron
Senior Member
 
Registered: Jan 2011
Location: Australia
Distribution: OpenSUSE
Posts: 1,390
Blog Entries: 7

Rep: Reputation: 164Reputation: 164
what does "&" mean in the terminal


Hello guys, i am struggling to find out what symbols mean such as '&', in the command line. google doesn't detect symbols and there doesn't seem to be any man pages.
If someone could post a good link that can help me out on this, that'll be great.
 
Old 02-16-2012, 10:44 PM   #2
cbtshare
Member
 
Registered: Jul 2009
Posts: 610

Rep: Reputation: 42
it means to run in the background.. so if you issue a command and give & after the command the screen output wont be shown.
 
Old 02-16-2012, 10:53 PM   #3
liberalchrist
Member
 
Registered: Jun 2011
Location: Chester, SC
Distribution: Slackware Current
Posts: 123

Rep: Reputation: 26
You will probably have to check a bash reference manual for this one. There are several of these as well as a ton of reserved words. The "&" symbol itself really just chains together commands. This is useful in a script where you need to execute one command then another. On the command line you can put several commands on the same line and they will execute one after another. This is commonly used in the xinitrc files in XOrg.
 
Old 02-17-2012, 12:25 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
cbt is correct, liberalchrist is confusing & with && (logical and).


Bookmark this lot
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
1 members found this post helpful.
Old 02-17-2012, 06:29 AM   #5
liberalchrist
Member
 
Registered: Jun 2011
Location: Chester, SC
Distribution: Slackware Current
Posts: 123

Rep: Reputation: 26
The man page you want is man bash . If you prefer a link, try this:

http://linux.about.com/library/cmd/blcmdl1_bash.htm
 
Old 02-17-2012, 06:39 AM   #6
Peverel
Member
 
Registered: May 2009
Location: Chelmsford, England
Distribution: OpenSuse 12.2 and 13.2
Posts: 104

Rep: Reputation: 21
cbtshare is correct, but "run in the background" may be a bit misleading: it actually spawns the command issued. Suppose you issue the command
kwrite
then kwrite will open in a new window, but the terminal will not receive a new prompt until that window is closed. On the other hand,
kwrite &
will open the new window in the same way, but the terminal will receive the new prompt immediately and may be used in parallel with kwrite.
 
2 members found this post helpful.
Old 02-17-2012, 03:01 PM   #7
josecolella
Member
 
Registered: Nov 2010
Location: Milan, Italy
Distribution: Linux Mint 13, Debian 6.0
Posts: 62

Rep: Reputation: 3
@Peverel is right...Thanks for posting an example of how to use it...
 
Old 02-18-2012, 06:50 AM   #8
Peverel
Member
 
Registered: May 2009
Location: Chelmsford, England
Distribution: OpenSuse 12.2 and 13.2
Posts: 104

Rep: Reputation: 21
In my previous answer, I was commenting on cbtshare's response rather than the original question, but context is all: chrism01 is actually wrong, & is a logical and symbol, but bitwise. In bash as in the C programming language all expressions evaluate to numbers. Logically, a zero number is false, all others are true; however, a true result evaluates to one, false to zero.
Now if expr1 and expr2 are expressions, then
expr1 && expr2
evaluates to 1 if both are true, otherwise 0, so that
19 && 21
returns 1 (or true, in context).
Now 19 in binary is 10011 and 21 is 10101. Now
19 & 21
returns the bitwise and of these, which is 10001, that is 17 (or, again, true in context). Note also that, since 12 is 01100, then
19 & 12
is 00000 (0, false), whereas
19 && 12
is one (true).
So, be careful, an & at the end of a line is a very different from one in the middle. Also, bash tends to need brackets, which I have ignored for simplicity.
 
Old 02-18-2012, 07:54 AM   #9
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
&& in bash is not logical and, it is a control operator

a logical and performs operation with 2 values and output a result, a control operator performs a control function

man bash
Code:
 AND and OR lists are sequences of one of more  pipelines  separated  by
the  &&  and  || control operators, respectively.  AND and OR lists are
executed with left associativity.  An AND list has the form
       
              command1 && command2
   
command2 is executed if, and only if, command1 returns an  exit  status
of zero.
 
Old 02-18-2012, 11:48 AM   #10
Peverel
Member
 
Registered: May 2009
Location: Chelmsford, England
Distribution: OpenSuse 12.2 and 13.2
Posts: 104

Rep: Reputation: 21
Cedrik: yes, you are right that && is a control operator, as is &, but in the bash man page you will also find, under
Code:
ARITHMETIC EVALUATION
the text
Code:
       &      bitwise AND
       ^      bitwise exclusive OR
       |      bitwise OR
       &&     logical AND
       ||     logical OR
which work as I indicated. Probably as in C, if the first argument to && is 0 or to || is nonzero, the second is not evaluated, similar to control operators, if you assume that returning exit status zero is true, all else false. However, since that analogy breaks down for &, it is perhaps dangerous.
 
Old 02-18-2012, 11:55 AM   #11
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Bash treats the arithmetic operators as arithmetic operators when they are found in arithmetic expressions which is:
  • In let <arithmetic expression>
  • In (( <arithmetic expression> ))
  • In array subscripts, that is in ${array[ <arithmetic expression> ]}
EDIT: Bash treats the logical operators as logical operators when they are found in test expressions which is:
  • In test <test expression>
  • In [ <test expression> ]
  • In [[ <test expression> ]]
EDIT 2: Bash treats the list operators && and || as list operators when they are found in lists of commands, that is command1 && command2 and command1 || command2 (allowing either command to itself be a list allows command1 && command2 || command3 and vice versa.

Last edited by catkin; 02-18-2012 at 12:05 PM.
 
Old 02-18-2012, 02:43 PM   #12
liberalchrist
Member
 
Registered: Jun 2011
Location: Chester, SC
Distribution: Slackware Current
Posts: 123

Rep: Reputation: 26
This has certainly been an informative thread, though I think the original poster just wanted appropriate reference material concerning symbols or operators "such as &".
 
Old 02-19-2012, 12:31 AM   #13
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by liberalchrist View Post
This has certainly been an informative thread, though I think the original poster just wanted appropriate reference material concerning symbols or operators "such as &".
Sometimes simple questions have complicated answers
 
Old 02-19-2012, 02:54 AM   #14
uhelp
Member
 
Registered: Nov 2011
Location: Germany, Bavaria, Nueremberg area
Distribution: openSUSE, Debian, LFS
Posts: 205

Rep: Reputation: 43
and don't forget another usage:
Code:
command  2>&1
 
Old 02-19-2012, 03:19 PM   #15
Knightron
Senior Member
 
Registered: Jan 2011
Location: Australia
Distribution: OpenSUSE
Posts: 1,390
Blog Entries: 7

Original Poster
Rep: Reputation: 164Reputation: 164
woh. yeah this post has gotten a lot more technical than I'd expected it too. thanks for your detailed explanations. a lot of it is going over my head at the moment. I need to sit down and really evaluate all this lol. thanks.
 
  


Reply


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
[SOLVED] "Insert" & "Delete" key returns "~" in a terminal. sharky Linux - General 15 04-26-2011 09:36 AM
detaching a (graphical)process invoked without "&" from terminal deepclutch Programming 2 06-07-2010 10:20 AM
"kdesu" daemon gives error message & all terminal emulators hang hari_seldon99 Mandriva 0 07-28-2004 05:30 AM
"kdesu" daemon gives contradictory error message & all terminal emulators hang hari_seldon99 Linux - General 0 07-24-2004 04:42 PM
"kdesu" daemon gives contradictory error message & all terminal emulators hang hari_seldon99 Linux - Software 0 07-21-2004 12:01 PM


All times are GMT -5. The time now is 04:27 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration