[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to test a object name is an executable ?
From: |
Budi |
Subject: |
Re: How to test a object name is an executable ? |
Date: |
Thu, 31 Aug 2023 07:34:58 +0700 |
Must be pure Bash only to prevent costly execution another
On 8/31/23, Seth David Schoen <schoen@loyalty.org> wrote:
> Budi writes:
>
>> 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
>
> It works with a full path:
>
> $ [[ -x /bin/ls ]] && echo YES
> YES
>
> If you don't know where in the system the executable in question is, you
> could run which in order to search the PATH to find out:
>
> $ [[ -x $(which ls) ]] && echo YES
> YES
>