0

I'm trying to set an environment variable and execute a command in a single line, like this:

export PUB_CACHE=/app/src/.pub-cache && dart-sdk/bin/dart server.dart

(Don't ask why... it's complicated ;))

It's being invoked by someone elses script; and it fails like this:

export: `&&': not a valid identifier6:44 PM
export: `dart-sdk/bin/dart': not a valid identifier6:44 PM
export: `server.dart': not a valid identifier

It seems like the entire rest of the line is being passed to export. It's entirely possible it's due to the way they're running the command and I can't fix it, but it's also possibly just my Linux noobishness.

Is there something wrong with my command? Can I easily make it execute both things individually?

12
  • Just removing the &&. – cuonglm Apr 15 '16 at 17:53
  • I'm confused; won't that add it to what's being exported? I need the var defined and then Dart calling – Danny Tuppeny Apr 15 '16 at 18:20
  • 1
    is it really using bash, as you've tagged? It's acting almost like a Bourne (not Again) shell with the export syntax. Try breaking it into multiple lines (PUB_CACHE=...; export PUB_CACHE; dart-sdk/bin/dart...) – Jeff Schaller Apr 15 '16 at 18:51
  • The command works for me here (except that I don't have any dart installation, so the second part fails). Are you sure you're not using dash or any other shell? What does echo $0 print? What if you remove the && or replace it by ;? – Murphy Apr 15 '16 at 19:34
  • 2
    Not answering the question, but you want env, not export -- env VAR=thing someCommand, or with bash, just VAR=thing someCommand – glenn jackman Apr 15 '16 at 19:40
0

Managed to fix it with this:

env PUB_CACHE=/app/src/.pub-cache dart-sdk/bin/dart server.dart

Didn't realise you could pass commands on the end (thanks cuonglm for getting me on to this in the comments!)

1
  • 1
    env is not necessary here, PUB_CACHE=/app/src/.pub-cache dart-sdk/bin/dart server.dart will equally work. – jlliagre Apr 16 '16 at 12:31

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.