相关疑难解决方法(0)

在shell中,"2>&1"是什么意思?

在Unix shell中,如果我想要组合stderrstdout进入stdout流进行进一步操作,我可以在命令的末尾添加以下内容:

2>&1
Run Code Online (Sandbox Code Playgroud)

所以,如果我想head在输出上使用g++,我可以这样做:

g++ lots_of_errors 2>&1 | head
Run Code Online (Sandbox Code Playgroud)

所以我只能看到前几个错误.

我总是很难记住这一点,而且我不得不去查阅它,主要是因为我不完全理解这个特殊技巧的语法.

有人可以打破这个并按字符解释具体2>&1 意义吗?

unix bash shell redirect

2121
推荐指数
16
解决办法
103万
查看次数

如何获取错误输出并将其存储在变量或文件中

我在弄清楚如何获取错误输出并将其存储在 ksh 中的变量或文件中时遇到了一些麻烦。所以在我的脚本中我有cp -p source.file destination一个while循环。

当我收到以下错误时

cp: source.file: The file access permissions do not allow the specified action.
Run Code Online (Sandbox Code Playgroud)

我想抓取它并将其存储在变量或文件中。

谢谢

unix permissions shell

4
推荐指数
1
解决办法
7681
查看次数

标签 统计

shell ×2

unix ×2

bash ×1

permissions ×1

redirect ×1