Tags:
create new tag
, view all tags
See BLT.

&: The ampersand has several uses, even several within the context of the shell:

  • & appended after a command causes the command to be executed in the background. If appended to a command that starts an X based program, the X based program starts and runs, while the command prompt returns to the shell so additional commands can be entered. It is the same as starting the command then typing Ctrl-Z to suspend it, and issuing the bg (background) command to start it running in the background.
  • && stands for the (bitwise?) and operator (in the context of C programming). In the shell it is one of the ''conditional execution'' operators. Placed between two commands on the command line, it will cause the second command to be executed only if the first is successful (returns a zero "exit code").
  • & in HTML marks "entities" (names for characters that are otherwise reserved for markup). It is an escape sequence that allows you to enter codes to display certain literal characters that would otherwise be interpreted as part of an HTML sequence. For example, to display a < it is necessary to enter the sequence "&lt;". (Note that in most HTML applications (browsers) that I've used, if you properly escape the first <, the corresponding > can be displayed without using the escape code. As many other things, this might be considered a bug or a feature). (Hmm, is that a function of the browser or the HTML server?) (It's browser dependent).

There's another use, as in:

swapon -a >/dev/console 2>&1

Here's a page that can explain most of the above -- I'm not sure why the initial redirect to /dev/console is needed (maybe it's not).

The use of & as part of a redirection operator in the shell causes the underlying file descriptor to be duplicated (using the dup() system call rather than open()). The practical effect is that this merges two output streams into one. The initial redirect closes the default stdout file descriptor and opens a new one on /dev/console. The other redirection then duplicates that file descriptor binding it to the file number used by stderr. Thus both of these are necessary in this case --- and the order is important. A command like:

swapon -a 2>&1 >/dev/console

... would bind stderr to the existing stdout stream (probably the terminal on which it was being run) and then close filescriptor one, opening a new stream on /dev/console — the errors would still be going to the old file/terminal.

Contributors

  • RandyKramer - 16 Feb 2002
  • JimDennis - 22 Sep 2003
  • <If you edit this page, add your name here, move this to the next line>
Edit | Attach | Watch | Print version | History: r9 < r8 < r7 < r6 < r5 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r9 - 2003-10-20 - JimDennis
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by PerlCopyright 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding WikiLearn? WebBottomBar">Send feedback
See TWiki's New Look