Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 5
    On some operating systems the empty string is treated as equivalent to . , so that [ -x '' ] may return true if the user has scan permission on the current directory; this leads to a false positive. (Fortunately this only affects a few older systems that are technically not POSIX compliant.) More resilient would be thing_path=$( command -v thing ) && [ -x "$thing_path" ] Commented Jan 2, 2023 at 3:24
  • 2
    Warning - this also fails for builtins: [ -x "$(command -v echo)" ]; echo $? prints 1! Commented Mar 28, 2023 at 11:18
  • @spawn right... with test also fails. Commented Dec 24, 2023 at 16:09
  • also fails if the command is aliased, alias pip='pip3'; [ -x "$(command -v pip)" ]; echo $? ` prints 1! Commented Apr 11 at 0:04