2016-04-09 11 views
0

マシンにコマンドがインストールされていない場合、依存関係のある小さなbashスクリプトを作成したいので、インストールします。依存関係を持つbashスクリプトを作成する

私が依存しているコマンドはjsonからnpm install json -gです。

それでは、私が探していることは、このようなものです:

checkcommand json --if `echo `"all good"` --else `npm install json -g` 

は、Mac用の端末のためにこのようなものはありますか?

+0

あなたは 'which'でテストしましたか? 'json && echo" jsonがインストールされているようなもの "||エコー "がインストールされていない、インストール中..." –

答えて

0

あなたが持つcheckcommandを実装することができ組み込みコマンドhash

checkcommand() { 
    # Clear the command's location from the cache... 
    hash -d "$1" 
    # ... then force the shell to look for it again 
    hash "$1" 2> /dev/null 
} 

if ! checkcommand json; then 
    npm install json -g 
fi