shellでcommandの存在を判定する
bash
type "command" > /dev/null 2>&1を使う
code:sh
if type "cowsay" > /dev/null 2>&1; then
sudo apt install cowsay
fi
from 【シェルスクリプト】コマンドの有無による条件分岐 - Qiita
予約語や函数とかぶらないよう、-Pをつけたほうがより確実かも
toc_id_5 | Bashシェルでtypeコマンドを使ってコマンドの存在チェックを行う際の注意 | ゲンゾウ用ポストイット
#2023-12-16 08:39:27
#2021-02-17 18:41:46