我目前正在研究一个脚本,它需要检查程序是否在第一次启动时安装。如果程序不存在,脚本将继续进行安装该程序所需的任何操作。到目前为止,我已经试过如下:如何防止在运行脚本时出现“type”stdout?
program_exist=$(type "someprogram" | grep "not found")
if ! "$someprogram_exist"; then
do some stuff
fi
program_exist=$(type "someprogram" 2>&1 >/dev/null | grep "not found")
if ! "$someprogram_exist"; then
do some stuff
fi
但每次我跑这个时候,我总是会见了以下消息:
./some_program.sh: line 8: ./some_program.sh: line 7: type: someprogram: not found: No such file or directory
有没有一种方法来检查程序是否存在而不是每次都显示./some_program.sh: line 8: ./some_program.sh: line 7: type: someprogram: not found: No such file or directory
消息?
看到http://stackoverflow.com/questions/592620/how-to-check-if-a-program-exists -from-a-bash-script –
谢谢!在该页 – lacrosse1991