Oct 19, 2016

[bash] do not use 'ls' to loop through dir files, use glob

ParsingLs
bash shopt man page


touch 'a space' $'a\nnewline'
echo "don't taze me, bro" > a
ls | cat
result:
a
a
newline
a space

---

using:
# shopt -s nullglob
to prevent generating literal '*' if directory has no files.
# Good! (Bash-only)
shopt -s nullglob
for f in *; do
    ...
done

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.