Will this redirection ">>& <filename>" work in Korn shell?
I am trying to redirect both STDOUT/STDERR of a UNIX command and append to a log file in a korn shell.
rm -rf file1 >>& logfile
Will this command work in ksh or is this a typical bash command?
What harm would I be causing with above command?
如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。

评论(3)

I use this form to redirect standard output and standard error to the same file.
ls -ld . fred > no_fred 2>&1
Just tested in Red Hat Linux 4's Korn shell. no_fred contains:
ls: fred: No such file or directory
drwxrwxr-x 2 user group 1024 Apr 27 17:41 .
">" is actually 1>, which says to redirect file descriptor 1 (standard output). "2>" redirects standard error, since standard error is file descriptor 2. "&1" means "whatever you're doing with file descriptor 1". So all together, this means "dump standard output into a file, and standard error along with it."
One advantage of this method is that error messages appear in the right place. For example, a compiler's error messages, for a file which failed to compile, will appear right after the compilation command from your makefile.
The >>& construct might append the output of the command to the log file, and puts this in the background. I'm not sure it does anything with standard error. I just consulted Bolsky/Korn 1989, and it's not even in there, so maybe someone else can parse what it does.
Update: If you have any pipes in your command, then the standard
error of early stages will appear first, as the error-producing command
runs. Since only the standard output is routed through the pipe, it will
all appear at once when the entire pipeline completes.
发布评论
需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。