For example this line fails:
$ nohup for i in mydir/*.fasta; do ./myscript.sh "$i"; done > output.txt& -bash: syntax error near unexpected token `do
What's the right way to do it?
At its most basic, nohup can be used with only a single argument, the name of the script / command that we want to run. For example if we had a Bash script called test.sh we could run it as so. If the script / command produces standard output, then that output is written to nohup.
jmoh/nohup with for loop Example of nohup command when using a for-loop. Basically, put for-loop statement in-between quotes and then throw "bash -c" in front of it.
To run a nohup command in the background, add an & (ampersand) to the end of the command. If the standard error is displayed on the terminal and if the standard output is neither displayed on the terminal, nor sent to the output file specified by the user (the default output file is nohup. out), both the ./nohup.
A bash for loop is a bash programming language statement which allows code to be repeatedly executed. A for loop is classified as an iteration statement i.e. it is the repetition of a process within a bash script. For example, you can run UNIX command or task 5 times or read and process list of files using a for loop.
Because 'nohup' expects a single-word command and its arguments - not a shell loop construct. You'd have to use:
nohup sh -c 'for i in mydir/*.fasta; do ./myscript.sh "$i"; done >output.txt' &
You can do it on one line, but you might want to do it tomorrow too.
$ cat loopy.sh #!/bin/sh # a line of text describing what this task does for i in mydir/*.fast ; do ./myscript.sh "$i" done > output.txt $ chmod +x loopy.sh $ nohup loopy.sh &
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With