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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
07-20-2012, 01:53 PM
|
#1
|
Member
Registered: Sep 2005
Location: New Jersey, USA
Distribution: VMware V12 and V15 in Windows 10, MX Linux 23.1, Kubuntu 23.10, IBM z/VM 5.4
Posts: 567
Rep:
|
Use of & in the bash shell.
Can anyone tell me what the '&' symbol does in the bash shell.
I do a 'echo &' and this shows me output as follows but being a newbie I have no idea what elese I can use the '&' sysbol for.
[root@centos5 ~]# echo &
[1] 3701
[root@centos5 ~]#
[1]+ Done echo
[root@centos5 ~]#
|
|
|
07-20-2012, 02:02 PM
|
#2
|
Senior Member
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238
Rep: 
|
If you have your terminal started and you type in "medit" and hit Enter, medit will start and you won't be able to use that terminal until you close medit. But if you type in "medit &" you'll be able to use terminal without closing medit. So you can use one terminal instance to start any amount of apps you like with "&".
|
|
|
07-20-2012, 02:04 PM
|
#3
|
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852
|
A single ampersand at the end of a command forks the process into the background, so the shell can continue onto the next operation without having to wait for it to finish. The output you get is the process number, as reported by the shell's job control feature. It's rather pointless to use it with commands that terminate instantly, though, like echo.
The ABSG has a whole page that lists almost all characters that have special meanings.
http://www.tldp.org/LDP/abs/html/special-chars.html
And the Bash Guide covers most of the important basics like this.
http://mywiki.wooledge.org/BashGuide
|
|
1 members found this post helpful.
|
07-21-2012, 03:55 AM
|
#4
|
Senior Member
Registered: Jan 2011
Location: Australia
Distribution: openSUSE
Posts: 1,469
|
additionally, '&&' will run one command after another. example: the two commands, 'apt-get update', and 'apt-get dist-upgrade' are two separate commands but can be linked with the '&&' by:
Code:
apt-get update && apt-get dist-upgrade
|
|
|
07-21-2012, 05:24 AM
|
#5
|
Moderator
Registered: May 2001
Posts: 29,415
|
BTW, I don't know if anybody noticed this, but testing things as root is one road to ruin, new Linux user or not. To minimize SNAFUs best use your unprivileged user account for that and only switch to root if required.
|
|
1 members found this post helpful.
|
07-21-2012, 01:36 PM
|
#6
|
Senior Member
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290
|
Quote:
Originally Posted by Knightron
additionally, '&&' will run one command after another. example: the two commands, 'apt-get update', and 'apt-get dist-upgrade' are two separate commands but can be linked with the '&&' by:
Code:
apt-get update && apt-get dist-upgrade
|
Actually, when && is used, the second command will only be run if the first command succeeds. This is because && is the logical AND operator. The way bash evaluates logical expressions, a logical AND will always fail if any of the subexpressions is FALSE. Therefore, if the first command in the string fails, the second will not be executed as the expression has already failed. The opposite behavior is given by || (logical OR), which will execute commands until any one of them succeeds. If you want all commands in a string to be run regardless of the success or failure of any individual command, they should be separated by semicolons ( ; ).
|
|
2 members found this post helpful.
|
All times are GMT -5. The time now is 08:12 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|