Re: OT: bash script - unexpected exit
- From: Dave Ihnat <dihnat@xxxxxxxxxx>
- Date: Mon, 16 Jan 2012 16:10:45 -0600
On Mon, Jan 16, 2012 at 09:25:30PM +0100, Andre Speelmans wrote:
I was not trying, the OP had a script that did a:
cat file | while read line; do something done
Matthew commented that you should not rely on cat for reading a file
line by line and I was curious as to why not. ...
I'm not aware of any particular reason not to use 'cat', and while it
doesn't cost a lot, it's usually less expensive to use redirection.
I just wanted to remind people that another way to redirect input (and
output) is through the exec command. For instance:
while read INLINE
would read lines from file "/usr/tmp/foo" and output them to
"/usr/tmp/bar", all within the shell. Moreover, any errors (should be none
with something this simple, of course) would go to "/usr/tmp/error" as
But wait! There's more!
You can redirect to/from any numeric file descriptor. For instance:
while read INLINE <&3
would open file descriptor 3 on "/usr/tmp/foo", and the "while read" will
walk through that file line by line.
You can close descriptors in a script when done with them, e.g.,
would close that descriptor opened in the above script snippet.
users mailing list
To unsubscribe or change subscription options:
Have a question? Ask away: http://ask.fedoraproject.org
- Prev by Date: Re: OT: bash script - unexpected exit
- Next by Date: Re: Mounting a partition within a dd image of a windows drive
- Previous by thread: Re: OT: bash script - unexpected exit
- Next by thread: Re: OT: bash script - unexpected exit