help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to test a object name is an executable ?


From: Greg Wooledge
Subject: Re: How to test a object name is an executable ?
Date: Wed, 30 Aug 2023 20:54:36 -0400

On Thu, Aug 31, 2023 at 07:17:22AM +0700, Budi wrote:
> How  do we test an object name / string is an executable, as tried it
> won't work:
> 
> $ [[ -x cp ]] &&echo YES
> $
> $ [[ -x ls ]] &&echo YES

https://mywiki.wooledge.org/BashFAQ/081

    POSIX specifies a shell builtin called command which can be used
    for this purpose:

    # POSIX
    if command -v qwerty >/dev/null; then
      echo qwerty exists
    else
      echo qwerty does not exist
    fi

Plus alternatives.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]