我正在尝试创建一个小脚本来检查程序是否已安装。 我正在尝试使用tmux,...
`tmux --help` | grep "tmux: command not found" &> /dev/null
if [ $? == 1 ]; then
echo "tmux is not installed"
exit
fi
安装了tmux后,我得到了以下提示:
usage: tmux [-2lquvV] [-c shell-command] [-f file] [-L socket-name]
[-S socket-path] [command [flags]]
tmux is not installed
如果某个程序未安装,则会显示字符串“tmux: command not found”。这可以解释为什么我要grep
tmux --help
命令的输出。这是检查tmux是否已安装的正确方法吗?该脚本始终会输出“tmux未安装”,即使我已经安装了tmux。它有什么问题?
tmux --help
周围加上反引号,因为这会执行tmux --help
并尝试将返回的帮助字符串作为命令执行。 - Etan Reisner