简体   繁体   中英

Bash: grep result of command using pattern from a different command?

I'm trying to grep the command df -h with a pattern that comes from a mysql command. Right now I have something like this:

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

Right now this is trying to grep the result of the mysql query instead of using the result as the pattern to grep the df result

The result of the mysql statement is "raid_48"

I will then want to pipe this into mailx. Maybe I shouldn't be trying to do this with a one liner

If there may be something wrong with your command you can consider these:

# 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")"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM