Bash-技巧 2017-06-09 脚本 Bash 0 评论 字数统计: 92(字) 阅读时长: 1(分)持续更新 Bash 小技巧检测程序是否已安装123456789101112131415#!/bin/bashcheck_software(){ local software=(vim git tmux npm) # 待测程序名 for soft in ${software[@]} do type $soft 2>&1 > /dev/null # 已安装,则返回零 if [ $? -ne 0 ]; then echo "ERROR: **$soft** is not installed!" exit 1 fi echo "Checking $soft...ok!" done}check_software123456运行结果bash check_software.shChecking vim...ok!Checking git...ok!Checking tmux...ok!Checking npm...ok!