So I borked an installation of a bin, and when I try to run the command (wasm-opt input_file.wasm) I get this:

/bin/sh: 1: /usr/local/lib/node_modules/wasm-opt/out/wasm-opt: not found

But that returns with exit code 0, So I can't check for error inside a bash script!

What I would like to do is check if the command exists, and if it does, run it. If it doesn't no problem, don't run it and just warn the user.

the usual wasm-opt input_file.wasm || echo "wasm-opt not installed" doesn't work.

  • 1
    I'm afraid there are several, unrelated issues in the code snippet you posted. I'd suggest you to check it using shellcheck.net as a first step.
    – fra-san
    Oct 1, 2020 at 15:26
  • ooh, good tip, thank you. Edited post to reflect the singular issue.
    – aName
    Oct 1, 2020 at 15:32
  • 1
    Please include the exact command you have tried, for the error you get.
    – thanasisp
    Oct 1, 2020 at 15:40

1 Answer 1


Not sure it's the best answer but you can feed the output of that command into grep and search for /bin/. Then we can match on whether or not grep found that text.

You must log in to answer this question.

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