When you type command that don't exists in your system bash runs function command_not_found_handle()
. In this function there is a call to /usr/lib/command-not-found
script that prints messages.
Ubuntu 12.04
My first guess to change source of this script to print messages to stdout
instead stderr
, but when I was reading source of script I found that you can configure it to just ask you if you want to install missing package.
If you export variable COMMAND_NOT_FOUND_INSTALL_PROMPT
you will be asked to install missing package:
pbm@ubuntu:~$ git
The program 'git' is currently not installed. You can install it by typing:
sudo apt-get install git
pbm@ubuntu:~$ export COMMAND_NOT_FOUND_INSTALL_PROMPT=""
pbm@ubuntu:~$ git
The program 'git' is currently not installed. You can install it by typing:
sudo apt-get install git
Do you want to install it? (N/y)y
sudo apt-get install git
[sudo] password for pbm:
Older versions of Ubuntu
Unfortunately there is no COMMAND_NOT_FOUND_INSTALL_PROMPT
so I can find few other options:
1) Install package from 12.04 - it shouldn't be the problem - it's only few scripts in Python so it should work (untested!).
2) Change stderr
to stdout
. To do it edit file /usr/lib/python2.7/dist-packages/CommandNotFound/CommandNotFound.py
and change stderr
to stdout
in lines 237 and 240.
After that you can use it in this way:
pbm@ubuntu:~$ git
The program 'git' is currently not installed. You can install it by typing:
sudo apt-get install git
pbm@ubuntu:~$ `git`
//Installation begins
If you add -y
option to apt-get
command in lines 237 and 240 you could also use syntax !! | sh
.
3) You can also modify this script from line 242 in this way:
print >> sys.stderr, _("You can install it by typing:")
f = open("%s/.install-missing" % os.path.expanduser('~'),'w')
print >> sys.stderr, "sudo apt-get install %s" % packages[0][0]
print >> f, "sudo apt-get install %s" % packages[0][0]
f.close()
In this way you will get your command in file ~/.install-missing
, so you may create alias:
alias im="chmod +x ~/.install-missing; ~/.install-missing"
If you call im
package will be installed.
cat out | netcat foo.bar.org 4000 > in &
I think the problem is that cat
will exit as soon as it receives an EOF
from the out
pipe. And when cat
exits, the rest of the pipeline (including netcat
) gets terminated as well.
Try something like this instead:
while true; do cat out; done | netcat foo.bar.org 4000 > in &
Thus, cat
gets restarted as often as needed, and any EOF
s appearing in the out
pipe are effectively handled.
Best Answer
This question is a duplicate and belongs to unix.stackexchange.com.
To sum up, still, the OpenGroup's Shell Command Language doc is relatively vague on details regarding "pipelines":
Note that while data clearly flows from "left to right" in the pipeline, there's no guarantee about the scheduling itself.
See also: