Linux - NewbieThis 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.
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.
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.
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.
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.
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.
&& 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.
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.
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.
This has certainly been an informative thread, though I think the original poster just wanted appropriate reference material concerning symbols or operators "such as &".
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.