BASH Shell Redirection

por | 20 agosto, 2008

Redirection Basics:

( < )STDIN - where to get input. i.e. keyboard, file ( > ) STDOUT – where to send processed info. i.e. Monitor, file
STDERR – where to send program error. i.e. monitor, background, file

< - STDDIN > – STDOUT – This redirects STDOUT from screen (default) to a file

>> – STDOUT – This represents APPEND mode

< - STDIN is usually read from a keyboard (console) or file | - PIPE - connects output of one program to input of another program awk field processor – searches lines and tokenizes fields.


-bash-3.00$ ls -lF /etc | grep rc | awk '{ print $1,$2,$8 }'
-rw-r--r-- 1 2007
lrwxrwxrwx 1 14:15
drwxr-xr-x 2 22:23
lrwxrwxrwx 1 14:15
drwxr-xr-x 2 22:23
lrwxrwxrwx 1 14:15
drwxr-xr-x 2 12:02
lrwxrwxrwx 1 14:15
drwxr-xr-x 2 22:23
lrwxrwxrwx 1 14:15
lrwxrwxrwx 1 14:15
lrwxrwxrwx 1 14:15
drwxr-xr-x 2 22:23
drwxr-xr-x 3 14:15
drwxr-xr-x 6 14:22
-rw-r--r-- 1 09:00
-rwxr-xr-x 1 2007
-rwxr-xr-x 1 2004



STDERR


Redirection – File Descriptors:

STDIN – 0
STDOUT – 1
STDERR – 2

-bash-3.00$ ls archivo_que_no_existe
archivo_que_no_existe: No such file or directory
-bash-3.00$ echo $?
2

to instruct ls to redirect file descriptor number two to a file

-bash-3.00$ ls archivo_que_no_existe 2> error.txt
-bash-3.00$ echo $?
2

ls archivo_queno_Existe 2> error.txt – redirects STDERR to file named ‘error.txt’

/dev/null –> all is discarted

-bash-3.00$ ls archivoquenoexiste 2>/dev/null
-bash-3.00$ echo $?
2

continua….
Final de STDERR y BASHH SHELL COMMAND CHAINING