How to connect two shell commands using pipes?

Q&A's, tips, howto's
Locked
ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

How to connect two shell commands using pipes?

Post by ale870 »

Hello,

i wanted to make a newLisp app to grab data from an extsting proces. Example:

>> ls /usr/share | grep init
initramfs-tools
initrd-tools
initscripts


As you can see, in the first line I used a "pipe" to connect "ls" command with "grep".
How can I get data input from shell pipe using newLisp (like grep in the previous case)? How can I send data output to shell pipe using newLisp (like ls in the previous case)?


thank you.
--

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Look for the sections about pipes and filters here:

http://www.newlisp.org/CodePatterns.html#scripts

we.g. with this program named 'upper'

Code: Select all

#!/usr/bin/newlisp

(while (read-line) (println (upper-case (current-line))))

(exit)
you could do:

Code: Select all

ls | ./upper
and would get an uppercase directory listing

Locked