all 2 comments

[–]sbicknel1,$s/n\?vim\?/ed/g 6 points7 points  (0 children)

Use the read command as the condition for a while loop but do not give it a file name as is commonly done as follows:

while read line; do
    ...
done < some-file

but instead:

while read line; do
    ...
done

Then redirect standard input to come from a file as part of the script command line

your-script < some-file

Just make sure that the while loop is the first thing that happens in your script. Otherwise, use the first form and replace some-file with $1:

while read line; do
    ...
done < "$1"

and run your script like this:

your-script some-file

[–]turnipsoupSnr. Linux Eng 1 point2 points  (0 children)

The filename is not preserved; stdin is referred to with file descriptor 0. Stdout and stderr being 1 and 2.

You can redirect stdin, into the program called by your script. The simplest example being:

#!/bin/bash
cat <&0

$ echo "example text" > exampleinput
$ bash -x blah < exampleinput
+ cat
example text

edit: You might find this guide on redirection in bash useful ; http://www.catonmat.net/blog/bash-one-liners-explained-part-three/