In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how shell output redirect", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "shell how to output redirect" this article.
Output redirection
If you wish, you can redirect the output of STDERR and STDOUT to an output file. For this reason, bash provides a special redirection symbol & >
Ls file nofile & > / dev/null
How do we redirect in the script? There is nothing special about it, just like a normal redirection.
#! / bin/bash#redirecting output to different locationsecho "now redirecting all output to another location" & > / dev/null
The question is, what if we want to redirect all the output to a file? We do not want to redirect every time we output, as the saying goes, the mountain people have their own brilliant plan. We can use exec to permanently redirect, as shown below:
#! / bin/bash#redirecting output to different locationsexec 2 > testerrorecho "This is the start of the script" echo "now redirecting all output to another location" exec 1 > testoutecho "This output should go to testout file" echo "but this should go the the testerror file" > & 2
The output is as follows:
This is the start of the scriptnow redirecting all output to another locationlalor@lalor:~/temp$ cat testoutThis output should go to testout filelalor@lalor:~/temp$ cat testerrorbut this should go the the testerror filelalor@lalor:~/temp$
To redirect as an append:
Exec 3 > > testout
Cancel the redirection:
Exec 3 >-what is shell? Shell is a program written in C that serves as a bridge for users to use Linux. Shell is both a command language and a programming language. Shell also refers to an application that provides an interface through which users access the services of the operating system kernel.
The above is all the content of the article "how to redirect shell output". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.