In a Bash script, if you want to run multiple commands with nohup without combining them into a single string, you can use one of these approaches:
nohup
Use { } to group commands and redirect output for the entire group:
{ }
nohup { command1 command2 command3 } > output.log 2>&1 &
output.log
&
Note: There must be a space after { and before }.
{
}
You can also use ( ) to run the commands in a subshell:
( )
nohup ( command1 command2 command3 ) > output.log 2>&1 &
If you want each command to have its own nohup and output file:
nohup command1 > output1.log 2>&1 & nohup command2 > output2.log 2>&1 & nohup command3 > output3.log 2>&1 &
Define a function and call it with nohup:
my_commands() { command1 command2 command3 } nohup my_commands > output.log 2>&1 &
Key Points:
> output.log 2>&1
nohup "command1; command2"
This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.
Vibe can make mistakes. Check answers. Learn more