[英]Bash: grep result of command using pattern from a different command?
我正在尝试使用来自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")"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.