Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to execute multiple command using nohup, And each command should execute after previous command, I used this command for example:

nohup wget $url && wget $url2 > /dev/null 2>&1 &

But this command didn't work. What is the command for this propose?

Any help would be much appreciated.

share|improve this question

4 Answers 4

up vote 26 down vote accepted

Wrap it in sh -c:

nohup sh -c 'wget "$0" && wget "$1"' "$url1" "$url2" > /dev/null &
share|improve this answer
when I launch nohup I get "nohup: ignoring input and redirecting stderr to stdout" so isn't the "2>&1" redundant? –  harschware May 14 '14 at 16:38
Probably. I think when I wrote the answer I just copied it from the question. –  jw013 May 14 '14 at 17:02

Others have already answered about nohup. As a practical side note: I recommend doing this kind of thing within a screen or tmux session. That way you can disconnect, then reconnect later and see the output and final result.

share|improve this answer

Wouldn't it be far simpler to create your list of commands in a separate shell file, e.g. command.sh, without any nohup.

Then you call:

nohup bash command.sh
share|improve this answer

It would be simpler like this:

nohup sh -c "wget $url && wget $url2" > /dev/null 2>&1 &

This however may cause issues if the URLs contain special characters so for a safer option you can use:

nohup sh -c "wget \"$url\" && wget \"$url2\"" > /dev/null 2>&1 &
share|improve this answer
The only safe way to pass parameters to sh -c is via separate arguments, which can be accessed via the positional parameters ($0, $1, ...). There is no easy or simple way to quote arguments properly for string parsing. Your attempt to use escaped double quotes fails if $url itself contains double quotes. Try a='problem"'; sh -c "echo \"$a\"" yourself and see - you should get a syntax error because sh -c tries to run echo "problem"". –  jw013 Sep 5 '12 at 15:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.