bash script regular expression
John Mellor
john.mellor at gmail.com
Fri Feb 10 13:36:09 UTC 2012
On Thu, 2012-02-09 at 23:31 -0800, Alejandro Rodriguez Luna wrote:
> . . .
> #/bin/bash
> for i in $(cat certificates.txt)
> do
> echo $i
> done
The problem is caused by the expected behaviour of the $(cat) construct
being fed into a for loop. It will use the current word separator to
split the text file into separate single-word lines for each word, which
is what lots of people want, but not what you expect in your situation.
Instead, use the read command like:
while read i
do
echo $i
done <certificates.txt
or:
cat certificates.txt | while read i
do
echo $i
done
and I think you will then see what you expect.
More information about the users
mailing list