I\'m trying to get the contents of a directory using shell script.
My script is:
for entry in `ls $search_dir`; do
echo $entry
done
Here's another way of listing files inside a directory (using a different tool, not as efficient as some of the other answers).
cd "search_dir"
for [ z in `echo *` ]; do
echo "$z"
done
echo * Outputs all files of the current directory. The for loop iterates over each file name and prints to stdout.
Additionally, If looking for directories inside the directory then place this inside the for loop:
if [ test -d $z ]; then
echo "$z is a directory"
fi
test -d checks if the file is a directory.