Linux command line and Shell script (11)--input/output REDIRECT __linux

Source: Internet
Author: User
Tags stdin
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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.