Redirecting a single command in a script to a file is straight-forward using the > syntax. For example, to redirect all STDERR output:
1 |
echo "hello, world" 2>> /tmp/filename.log
|
To redirect all lines of a Bash script to a file, add a scope around all of the lines and then redirect the scope to a file. For example:
1 2 3 4 5 6 |
( echo "this is line 1 of my script" cat /proc/cpuinfo dmesg echo "this is the end of my script" ) 2>> /tmp/filename.log |
This allows you to capture all output of a script without having to append the redirection to each line.





