简体   繁体   中英

bash “&” without printing “[1]+ Done ”

I call a script in my .bashrc to print number of new messages I have when I open the terminal, I want the call to be non blocking as it accesses the network and sometimes takes a few seconds which means I can't use the terminal until it completes.

However if I put:

    mailcheck & 

in my bashrc, it works fine. but then prints an empty line and I have when I press enter and it prints

    [1]+  Done                    ~/bin/mailcheck

This is very messy is there a way around this?

That message isn't coming from mailcheck, it's from bash's job control telling you about your backgrounded job. The way to avoid it is to tell bash you don't want it managed by job control:

mailcheck &
disown $!

这似乎有效:

(mailcheck &)

你可以这样调用你的脚本:

(exec mailcheck & )

try piping stderr to /dev/null

mailcheck & 2>/dev/null

Thinking about it for a few mins, another way might be to use write.
Pipe the output of the background task to yourself, that way it can complete at any time and you can bin any additional output from stdout as well as stderr.

mailcheck | write $(whoami) & > /dev/null

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM