我试图使用来自mysql命令的模式来命令df -h命令。现在我有这样的事情:
df -hP | grep $(mysql -uroot -e "select statement")
现在这是尝试grep mysql查询的结果,而不是使用结果作为模式来grep df结果
mysql语句的结果是" raid_48"
然后我想把它传递给mailx。也许我不应该尝试用一个班轮
来做这件事答案 0 :(得分:2)
如果您的命令可能出现问题,您可以考虑这些:
# 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")"