So I've got a script that runs test cases on another script. I'm trying to redirect stderr while running the test cases. The part that is giving me problems is the read command:
within script1:
read -p "Delete $file? (y/n) " input
within testscript:
$script $opts $file 2>/dev/null
The read calls from script1 get redirected as well.
&1 is used to reference the value of the file descriptor 1 (stdout). Now to the point 2>&1 means “Redirect the stderr to the same place we are redirecting the stdout” Now you can do this.
The regular output is sent to Standard Out (STDOUT) and the error messages are sent to Standard Error (STDERR). When you redirect console output using the > symbol, you are only redirecting STDOUT. In order to redirect STDERR, you have to specify 2> for the redirection symbol.
Redirect the prompt to stdout.
read -p "Delete $file? (y/n) " input 2>&1
You can go simple:
echo "Delete $file? (y/n)"
read input
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With