> -----Original Message-----
> From: Leonard den Ottolander
> Subject: Bash: read and backslashes in input file
>
>
> Hi,
>
> Consider the following example:
> while read line; do echo ${line}; done < somefile
> read will interpret the backslashes as escapes and remove
> them from the input. Now I could do
> sed s/'\\'/'\\\\'/ somefile | while read line; do echo ${line}; done
> , but this will create a subshell which is not what I want
> (need to set some global variables in the while loop).
> Is there a way that I could pipe the output from sed (or any
> command) into the while loop without creating a subshell (ie as in the
> first example)?
>
> Bye,
> Leonard.
If your not interested in performance issues of your
script... another approach could use 'for' instead of 'while'.
Example:
Given a file called 'testfile' that contains simply:
Line 1
Line 2
Line 3
#!/bin/sh
for line in `sed s/'Line'// testfile`
do
[ ${line} -eq 2 ] && global_var=${line}
done
echo ${global_var}
Steve Cowles
--
redhat-list mailing list
unsubscribe mailto:redhat-list-request@;redhat.com?subject=unsubscribe
https://listman.redhat.com/mailman/listinfo/redhat-list