Suppose we have to run following UNIX bash shell loop construct under 'nohup'
$ for i in $(seq 20); do echo $i;./somescript.sh $i; done
Running the above loop under nohup directly will not work as 'nohup' expects a single-word command and its arguments. This is how we can run a UNIX bash shell loop construct using 'nohup'.
$ nohup sh -c 'for i in $(seq 20); do echo $i;./somescript.sh $i; done' &
From man page of 'sh'
-c Read commands from the command_string operand instead of from the
standard input. Special parameter 0 will be set from the command_name operand
and the positional parameters ($1, $2, etc.) set from the remaining argument operands.
Related post:
- Setsid : Run UNIX program in a new session
- More about UNIX seq command
No comments:
Post a Comment