Thursday, 12 September 2013

How to make a bash script to read from stdin

How to make a bash script to read from stdin

I have some scripts that work with parameters, they work just fine but i
would like them to be able to read from stdin, from a pipe for example, an
example, suppose this is called read:
#!/bin/bash
function read()
{
echo $*
}
read $*
Now this works with read "foo" "bar" I would like to use it as:
echo "foo" | read
How do i accomplish this?

No comments:

Post a Comment