Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop a zsh script from being suspended (tty output)

I have a zsh script that I want to run such that it also loads up my .zshrc file. I believe I have to run my script in interactive mode?

Thus, my script begins like:

#!/bin/zsh -i

if [ $# = 0 ]
then
    echo "need command line paramter..."
    exit
fi

However, when I try to run this script in the background, my script becomes suspended (even if I pass in the correct number of parameters):

[1]  + suspended (tty output) 

My question is: How can I make a script that can run in the background that also loads my startup .zshrc file? If I have to put it into interactive mode, how can I avoid the suspension on tty output problem?

Thanks

like image 600
Peter991 Avatar asked Jun 21 '11 20:06

Peter991


1 Answers

Don't use interactive mode as a hash-bang!

Instead, source your zshrc file in the script if you want it:

#!/bin/zsh
source ~/.zshrc
...

For future reference, you can use the disown bultin to detach a previously backgrounded job from the shell so it can't be suspended or anything else. The parent shell can then be closed with no affect on the process:

$ disown %1

You can do this directly from the command line when you start the program by using the &! operator instead of just &:

$ ./my_command &!
like image 77
Caleb Avatar answered Oct 22 '22 06:10

Caleb