Linux

Bash,檢查軟體的腳本

  • October 10, 2016

我在 bash 上有一個腳本:

s=0
if [ -f /usr/bin/curl ] && [ -x /usr/bin/curl ] ; then
   echo  "Utility ...... curl [ ok ]"
   else
   echo  "Utility ...... curl [fail]"
   s=1
fi
if [ -f "/bin/grep" ] && [ -x "/bin/grep" ] ; then
   echo  "Utility ...... grep [ ok ]"
   else
   echo  "Utility ...... grep [fail]"
   s=1
fi
if [ -f "/usr/bin/expr" ] && [ -x "/usr/bin/expr" ] ; then
   echo  "Utility ...... expr [ ok ]"
   else
   echo  "Utility ...... expr [fail]"
   s=1
fi
if [ -f "/bin/sed" ] && [ -x "/bin/sed" ] ; then
   echo  "Utility ...... sed  [ ok ]"
   else
   echo  "Utility ...... sed  [fail]"
   s=1
fi
if [ $s -eq 0 ]; then
   echo  "All seems to be good. Let's play."
else
   echo  "Please install requirement util! "
fi

我想在沒有 /usr/bin 或 /bin 的情況下編寫。我想寫一個變數:

$ENV/curl

和其他人……

如何做到這一點。

if [ -x "$(which curl)" ] ; then
   echo  "Utility ...... curl [ ok ]"
   else
   echo  "Utility ...... curl [fail]"
   s=1
fi

引用自:https://serverfault.com/questions/808128