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 Answers1

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 )?

Celada
  • 44,132