nohup VERBOSE=1 perl script.pl

bobox picture bobox · Jan 11, 2012 · Viewed 7.8k times · Source

I have a perl script for which ENV variables can be set to direct specific outputs e.g. $debug, $verbose, $develop etc

Usually I run these from the command line

$ VERBOSE=1 perl myperlscript.pl params

I now want to run them using nohup. Using the command line

$ nohup VERBOSE=1 perl myperlscript.pl params 

is clearly not right, as the attempt to set ENV{VERBOSE} is interpreted as a param to nohup & I get the msg

nohup: failed to run command `VERBOSE=1': No such file or directory

What IS the correct syntax here? I'm trying to run this on a linux box.

Answer

pilcrow picture pilcrow · Jan 11, 2012

Set the environment variable before calling nohup, and it will be preserved when nohup exec()s (replaces itself with) perl.

$ VERBOSE=1 nohup perl myscript.pl params ...