1

i have a script on 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

I want write without /usr/bin or /bin. I want write one variable:

$ENV/curl

And others ...
How to do this.

1 Answer 1

1
if [ -x "$(which curl)" ] ; then
    echo  "Utility ...... curl [ ok ]"
    else
    echo  "Utility ...... curl [fail]"
    s=1
fi
4
  • it is ok. but, i need to use one variable to all environments
    – Valeriu
    Oct 10, 2016 at 13:33
  • You should use only if [ -x "$(which curl)" ]. If a command exists then , which will return the full path and -x will check for executable.
    – gloom700
    Oct 10, 2016 at 14:28
  • "which" command will search for the file in all the paths defined in $PATH variable. If you want to search other directories you can add the path in the $PATH variable.
    – gloom700
    Oct 10, 2016 at 14:31
  • I have edited my answer. If you do not want to write /usr/bin , /bin you can use "which"
    – gloom700
    Oct 10, 2016 at 14:39

Not the answer you're looking for? Browse other questions tagged .