linux命令输出到变量
将linux的命令输出重定向到变量。
最近mac装了nginx,想看一下默认配置文件的位置:
nginx -V | grep 'conf'
发现没有输出,不知道什么原因。
曲线救国,将命令输出到变量,再grep。
OUTPUT=$(nginx -V 2>&1)
echo $OUTPUT | grep conf
参考:
https://stackoverflow.com/questions/10319745/redirecting-command-output-to-a-variable-in-bash-fails