0

If I run

export COMMAND=nonexistentcommand && which $COMMAND >/dev/null || \
(echo "download filewithcommand.sh" && export COMMAND=./filewithcommand.sh)

echo "command: $COMMAND"

I get

download filewithcommand.sh
command: nonexistentcommand

But I think it should be

download filewithcommand.sh
command: ./filewithcommand.

What's wrong with this sentence?

1
3

COMMAND is set to nonexistentcommand and that's the output that you get. Normal.

You do set COMMAND to some other value, but that's in a subshell (enclosed in parentheses) so it doesn't affect the environment of the parent shell. Did you mean to use { braces } (which don't fork a subshell) instead of ( parentheses )?

1
  • Yeah. This is the good response. You are great ;). I just have had to add an ending semicolon at the end of the last command. – Manel R. Doménech Feb 28 '16 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.