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

1 Answer 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. Commented Feb 28, 2016 at 19:37

You must log in to answer this question.

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