20

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

Vincent
  • 303
  • 1
  • 2
  • 5

1 Answers1

30

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"
    
AProgrammer
  • 2,278
  • 18
  • 15