Bash scripting
6/48
Traditional service delivery
Redirection: Examples
●
Stdout redirected to file
find . -name pippo > find-output.txt
●
Stderr redirected to file
find . -name pippo 2> find-errors.txt
●
discards any errors that are generated by the find command
find / -name "*" -print 2> /dev/null
/dev/null is a simple device (implemented in software and not corresponding to any
hardware device on the system).
/dev/null looks empty when you read from it.
Writing to /dev/null does nothing: data written to this device simply "disappear."
Often a command's standard output is silenced by redirecting it to /dev/null, and this is
perhaps the null device's commonest use in shell scripting:
command > /dev/null
●
Redirect both stdout and stderr to file
find . -name pippo &> out_and_err.txt
●
Redirect stderr to stdout: find . -name filename 2>&1
●
Redirect stdout to stderr: find . -name filename 1>&2