gpt4 book ai didi

linux - Bash:使用来自不同命令的模式的命令的grep结果?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:19:22 26 4
gpt4 key购买 nike

我正在尝试使用来自 mysql 命令的模式来 grep 命令 df -h。现在我有这样的东西:

df -hP | grep $(mysql -uroot -e "select statement")

现在这是尝试 grep mysql 查询的结果,而不是使用结果作为模式来 grep df 结果

mysql语句的结果是“raid_48”

然后我想将其通过管道传输到 mailx 中。也许我不应该尝试用一个衬垫来做这件事

最佳答案

如果您的命令可能有问题,您可以考虑这些:

# Add `-e` before the argument to explicitly tell grep that the argument that follows is an expression not an option.
# Quote your argument to prevent word splitting with spaces.
df -hP | grep -e "$(mysql -uroot -e "select statement")"

# Perhaps try using fgrep as well to prevent reading argument as regex.
df -hP | fgrep -e "$(mysql -uroot -e "select statement")"

关于linux - Bash:使用来自不同命令的模式的命令的grep结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24745068/

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