(I'm editing an existing Bash script, so I'm probably making a silly mistake here...)

I have a shell script that saves a command with an environment variable as its argument like this:

COMMAND="mvn clean install -P $MAVEN_PROFILE"

It then executes the command with nohup roughly as follows:

nohup $COMMAND > logfile

This works.

Now, I want to set an environment variable that can be accessed in Maven. I've tried several things like the following:

COMMAND="FORMAVEN=valueForMaven mvn clean install -P $MAVEN_PROFILE"

...but then it just terminates with:

nohup: failed to run command `FORMAVEN=valueForMaven': No such file or directory

I feel like there are several unrelated concepts at work here, none of which I understand or even know about. What do I need to be able to do the above?


Three methods:

  • set (and export) the variable before launching mvn

  • set the variable on the nohup launch:

    FORMAVEN=valueForMaven nohup $COMMAND > logfile
  • use env to set the variable

    COMMAND="env FORMAVEN=valueForMaven mvn clean install -P $MAVEN_PROFILE"
  • Excellent! I knew it had to be easier than the directions I was thinking of... – Vincent Sep 7 '16 at 8:52

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.