I guess this is obvious to most people but it took me quite a while to dig it out on the internet. I wanted my bash script to be able to read from standard input like cat sourcefile.txt|bash myscript.bash. It turns out the standard input can be read from /dev/stdin. So if I wanted to sort the standard input, myscript.bash would look like: sort /dev/stdin
I think this is probably basic UNIX knowledge but I’m not a programmer.
J | 11-Jun-07 at 9:49 am | Permalink
It’s unnecessary to call “bash myscript.bash”
Set your script executable:
chmod +x myscript.bash
and then run it as:
cat sourcefile.txt | ./myscript.bash
ScottS-M | 11-Jun-07 at 10:13 am | Permalink
That’s true. I tend to be lazy and just call bash explicitly instead of using chmod and adding
#!/bin/bashto the first line of the script.firebush | 28-Jun-08 at 11:24 am | Permalink
Thanks, this was helpful.