2016-04-09 25 views
0

Makinede yüklü komutlardan birine sahip değilseniz, bağımlılıkla birlikte küçük bir bash komut dosyası oluşturmak istiyorum.Bağımlılık ile bash betiği oluşturun

Bağımlı olduğum komut numaralı telefondan npm install json -g numaralı telefondan. mac terminali Böyle bir şey

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

var mı:

Yani aradığım böyle bir şeydir?

+0

Eğer 'which' ile denediniz? json && echo "json'un yüklü olduğu" gibi bir şey || echo "yüklü değil, yükleniyor ..." –

cevap

0

Sen ile checkcommand uygulayabilirsiniz yerleşik komutu 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