How to prevent filename expansion in for loop in bash
Posted
by
cagri
on Stack Overflow
See other posts from Stack Overflow
or by cagri
Published on 2011-02-24T23:15:45Z
Indexed on
2011/02/24
23:25 UTC
Read the original article
Hit count: 224
In a for loop like this,
for i in `cat *.input`; do
echo "$i"
done
if one of the input file contains entries like *a
, it will, and give
the filenames ending in 'a'.
Is there a simple way of preventing this filename expansion?
Because of use of multiple files, globbing (set -o noglob
) is not a
good option. I should also be able to filter the output of cat
to
escape special characters, but
for i in `cat *.input | sed 's/*/\\*'`
...
still causes *a
to expand, while
for i in `cat *.input | sed 's/*/\\\\*'`
...
gives me \*a
(including backslash). [ I guess this is a different
question though ]
© Stack Overflow or respective owner