read the contents of a directory using shell script
Posted
by jrharshath
on Stack Overflow
See other posts from Stack Overflow
or by jrharshath
Published on 2010-03-12T19:47:17Z
Indexed on
2010/03/12
19:57 UTC
Read the original article
Hit count: 263
shell-scripting
|directory-listing
Hi,
I'm trying to get the contents of a directory using shell script.
My script is:
for entry in `ls`; do
echo $entry
done
However, my current directory contains many files with whitespaces in their names. In that case, this script fails.
What is the correct way to loop over the contents of a directory in shell scripting?
PS: I use bash.
© Stack Overflow or respective owner