understanding input and outputREDIRECT Error messages
Ls-al badfile 2> test4 redirection errors and data
Ls-al test test2 test3 badtest 2> test6 1> #错误输入到test6, normal data is displayed to Test7 test7 test ls-al &> test2 #将标准错误和 Standard input is redirected to Test8
Redirecting output in scriptOutput text to standard error echo "This is a error message" >&2 can use the EXEC command to tell the shell script to redirect a particular file descriptor during execution
echo "This is the start of the script";
echo "Now redirecting all output to another location";
EXEC 1> testout
exec 2> testerror
echo "This output should go to the Testout file";
echo "This output should go to the Testerror file" >&2;
REDIRECT input in scriptThe EXEC command allows stdin to be redirected to a file on a Linux system
File= "/users/chenhong/desktop/shell_workspace/std.sh";
EXEC 0< $file
count=1 while read line doing
echo "line $count: $line";
count=$[$count + 1];
Done
Create your own redirectYou can use the EXEC command to output an assignment file descriptor
EXEC 3>testout # can also use exec 3>>testout to append
echo "This shoud output the STDOUT";
echo "This shoud output the &3" >&3;
To turn off the file descriptor, redirect it to a special symbol &-exec 3>&-
List Open File descriptorsDisplays the default file descriptor for the current process lsof-a-P $$-D 0,1,2
block command outputAny data that the shell outputs to a null file is not saved so that they are lost. Ls-al >/dev/null can quickly remove data from existing files without deleting files and then creating Cat/dev/null > Testfile
Log MessagesThe tee command corresponds to a T-joint of a pipe. It will send data from stdin to two destinations at the same time. One destination is stdout, the other destination is tee. FileName specified in the command line date | Tee testout By default, tee overwrites files each time, appending files, and can use-a date | Tee-a Testout