pavement

Bash

From FreeBSDwiki
(Difference between revisions)
Jump to: navigation, search
m (Reverted edits by DavidYoung (talk) to last revision by 200.38.30.168)
 
(12 intermediate revisions by 6 users not shown)
Line 1: Line 1:
The Bourne Again Shell (located in /bin/bash) is the default shell of the [[Linux]] operating system and is the shell that users of that system will likely be most familiar with.
+
The Bourne Again Shell (located in /bin/bash) is the default [[shell]] of the [[Linux]] operating system and is the shell that users of that system will likely be most familiar with.
  
==Redirection in bash==
+
One of bash's strongest features, shared with the [[Bourne shell]], is flexible output [[redirection]].
Bash's shining moment comes for users who need to see and/or redirect errors to somewhere other than STOUT (your console). Standard input (STIN), standard output (STOUT) and standard error (STERR) are by default sent to the same place: STOUT (on most systems, this will be your console or tty). [[bash]] labels these descriptors 0, 1 and 2, respectively -- you have 10 descriptors, but only 0-2 are actually taken by anything. So
+
samizdata# myprogram > file
+
will send the output of ''myprogram'' to ''file''
+
samizdata# myprogram 2> file
+
will send only the '''error''' output of ''myprogram'' to ''file''
+
samizdata# myprogram 2>&1 | command
+
will send errors (descriptor 2,) to the same place as output (descriptor 1) and then pipe that to ''command2''
+
  
Okay, let's say you want to send output to your screen and errors to a file. You '''can't''' just do
+
Note: Bash is ''not'' available by default in the base system, but can easily be installed from [[:Category:Ports and Packages|ports]] if desired.
samizdata# myprogram 1>&2 2>&1 > errors.txt
+
because when you do the first switch, it's done ''right away'' and when the second >& comes around, it's getting the switched data. This is where the other, normally unused, file descriptors 3-9 come in. You can use them as place-holders, such as:
+
samizdata# myprogram 3>&2 2>&1 1>&3 | command
+
will make the output of ''myprogram'' do this: 3 point to the same place as 2, 2 point to 1, and finally, 1 point to 3 and then pipe all of it to ''command''
+
  
Seen [[bash]]'s [[man]] page for more info.
+
See [[bash]]'s [[man]] page for more info.
  
 +
see also: [http://cnswww.cns.cwru.edu/php/chet/bash/bashtop.html bash homepage]
  
Note: Bash is ''not'' available by default in the base system, but can easily be installed from [[:Category:Ports and Packages|ports]] if desired.
+
To change your shell from one to another, run the [[chsh]] command.
 +
 
 +
To change [[bash]]'s look and feel, edit your [[shell configuration file]] -- .profile and/or [[.bashrc]] (may be called .bash_profile on older systems).
  
 
Other shells that you can install and customize for ease of use are the [[bash]], [[tcsh]], [[psh]], [[ksh]], [[zsh]].
 
Other shells that you can install and customize for ease of use are the [[bash]], [[tcsh]], [[psh]], [[ksh]], [[zsh]].
  
see also: [http://cnswww.cns.cwru.edu/php/chet/bash/bashtop.html bash homepage]
+
See also [[Changing_your_shell]] and [[Gotchas, Linux]]
  
 
[[Category: Shells]]
 
[[Category: Shells]]
 
[[Category: Ports and Packages]]
 
[[Category: Ports and Packages]]
 +
[[Category : Linux Equivalents]]

Latest revision as of 17:25, 25 August 2012

The Bourne Again Shell (located in /bin/bash) is the default shell of the Linux operating system and is the shell that users of that system will likely be most familiar with.

One of bash's strongest features, shared with the Bourne shell, is flexible output redirection.

Note: Bash is not available by default in the base system, but can easily be installed from ports if desired.

See bash's man page for more info.

see also: bash homepage

To change your shell from one to another, run the chsh command.

To change bash's look and feel, edit your shell configuration file -- .profile and/or .bashrc (may be called .bash_profile on older systems).

Other shells that you can install and customize for ease of use are the bash, tcsh, psh, ksh, zsh.

See also Changing_your_shell and Gotchas, Linux

Personal tools