Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I open up 2 xterms on my desktop, A(/dev/pts/0) and B(/dev/pts/1).
I can write from A to B using redirection e.g. echo "test" > /dev/pts/1
How do I run a command from A on B? e.g. "clear"
Basically I'm putting the 2 terminals side by side, and using terminal B to display the contents of the current working directory, by running the following in A:
export PROMPT_COMMAND="ls -a > /dev/pts/1"
but this fills up the screen pretty fast. I was actually looking for a way to clear up the second terminal.
I'm no expert, but I don't think there's any simple way to do that. > simply redirects the stdout of one process to the stdin of another. Since you're not placing anything into the readline of the terminal, it can't actually execute anything.
Perhaps it would be possible to write a simple script that would run on the receiving end, which would parse the incoming data before echoing it to the screen, and run the clear command whenever that input contains a specified string.
Using evo2's named pipe suggestion, I whipped up this quick script. Any line fed into the pipe that begins with an @ symbol will be read as a command and executed. @exit will remove the pipe and exit the script. Everything else will be echoed straight to stdout. I set the pipe name to /tmp/catpipe by default, but you can easily change it.
Code:
#!/bin/bash
PIPE=/tmp/catpipe
trap "rm -f $PIPE" exit 1
[[ ! -p $PIPE ]] && mkfifo $PIPE
while true; do
while read line; do
case "$line" in
@exit) rm -f $PIPE && exit 0;;
@*) eval "${line#@}" ;;
* ) echo "$line" ;;
esac
done <$PIPE
done
exit 2
Edit: Whaddyaknow, pretty much the same solution as in EricTRA's link. In fact, I've gone ahead and incorporated the trap command in my script too, to make sure it cleans up when force-terminating the loop.
Last edited by David the H.; 09-10-2010 at 03:43 AM.
Reason: as above + a bit of re-formatting
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.