gpt4 book ai didi

linux - 如何捕获 'mount' 输出

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:41:26 25 4
gpt4 key购买 nike

我想我遗漏了一些非常愚蠢的东西,请纠正我。

root@fdas:~# mount /dev/sdd1 /b 2>&1 > /tmp/test

mount: you must specify the filesystem type
root@fdas:~# cat /tmp/test
root@fdas:~# mount /dev/sdd1 /b > test
mount: you must specify the filesystem type
root@fdas:~# cat test
root@fdas:~#

我只需要捕获那一行输出...在此先感谢您

最佳答案

看起来在标准 shell(不是 bash/csh)中你需要告诉它首先重定向 stdout 然后重定向 stderr,所以你只需要交换你的重定向:

mount /dev/sdd1 /b > /tmp/test 2>&1

在 CSH 中,您可以按照 Shiplu 的建议使用 &:

mount /dev/sdd1 /b >&  /tmp/test

在 BASH 中 & 语法不同:

mount /dev/sdd1 /b &>  /tmp/test

BASH 也支持 CSH & 语法,但不推荐(在 man 中)

关于linux - 如何捕获 'mount' 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8682940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com