0

I can easily pipe the output of a command like:

some_command | less

I can also easily play a sound after a command like:

echo test; print \\a 

aplay, beep or others could also be used for sound.

What I need is to do both, I mean, play the sound and pipe the output. Something like (it doesn't work)

 (echo test; print \\a ) | less

Of course, if I do this, the sounds play after less quits, which is not what I want:

echo test | less ; print \\a

This code works:

echo test > /tmp/tmp.txt ; print \\a ; less /tmp/tmp.txt 

However, I found it quite inelegant. There can be also annoying problems if executing more than one at the same time. They can be solved with a script, but it becomes unnecessarily complicated. Any better solution?

3 Answers 3

1

It seems that the overall goal is not to use the temporary file?
That's going to be nearly impossible not to involve a file.

If you want to avoid /tmp/tmp.txt you can use a FIFO.

mkfifo myfifo
(echo test; print \\a > /dev/tty) > myfifo &
less < myfifo
rm myfifo

You have to put it somewhere, but this might be a little more elegant than /tmp.

The echo test uses myfifo, and print \\a sends the alert character directly to /dev/tty. The & runs a subshell in the background, concurrently with less.

1

What about something like this:

echo test | (sleep 1; echo done) & speaker-test -t sine -f 1000 -l 1

This way your command (which is in the parenthesis, just for testing I put there a sleep to make it long running) will run in the background, and the sound (which is a loud sine wave in this example) will play.

If you need the command in the foreground, then you can do this:

(echo test; speaker-test -t sine -f 1000 -l 1 > /dev/null &) | less

Here piping the sound to /dev/null is needed, otherwise it will be piped into less, which is probably not desired.

0

After reading the answers, I realized that I could simple do:

(echo test; print \\a > /dev/tty ) | less

The problem with print was that the sound was done through the console, so a redirect solves the problem. With a console free way (like speaker-test or aplay) it would work without the redirection, though this is the simplest way, without an external program.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .