开发者

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

开发者 https://www.devze.com 2023-03-14 22:55 出处:网络
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?

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


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 &!
0

精彩评论

暂无评论...
验证码 换一张
取 消