redirections.sh (773B)
1 #!/usr/bin/env bash 2 # File : redirections.sh 3 # Description: Some redirection examples for stdout and stderr 4 # Copyright 2022 Harvard University. All Rights Reserved. 5 6 echo 'The `echo` command outputs to stdout:' 7 echo 'Hello CS107/AC207' 8 echo 'Hello CS107/AC207' >/dev/null # no output to stdout here 9 10 echo 'The `cp` command takes at least two arguments:' 11 12 cp >out1 # this will fail and print an error message on your screen. The stdout 13 # stream will be empty and so is the file out1 14 15 cp 2>/dev/null # this will redirect the stderr stream into /dev/null. You will 16 # not see the error message on your screen 17 18 cp >out2 2>&1 # this will redirect both stdout and stderr to the file out2. 19 # There will be no output on the screen