Search code examples
linuxbashnohupsubshell

Linux: run in subshell


I want to start a long-running process from a script that then exits, but I'm getting nowhere. Here's my most simple test. With each run, the console is blocked for 5 seconds.

// Create script
me@mine:~/workspace/bin$ cat > test.sh
sleep 5
// Verify script
me@mine:~/workspace/bin$ cat test.sh
sleep 5
// Make executable
me@mine:~/workspace/bin$ chmod 777 test.sh
// Expect to wait
me@mine:~/workspace/bin$ ./test.sh
// Expect to return, still waits
me@mine:~/workspace/bin$ ./test.sh ?
// Ditto
me@mine:~/workspace/bin$ nohup ./test.sh ?
nohup: ignoring input and appending output to 'nohup.out'
me@mine:~/workspace/bin$ 

I'm running Ubuntu 17.04 64, GNU bash, version 4.4.7(1)-release (x86_64-pc-linux-gnu)

I'm a Linux noob, and I'm sure I'm not getting something. Any help is appreciated.


Solution

  • Use ampersand: nohup ./test.sh &