How to get the list of files in a directory in a shell script?

前端 未结 10 1593
感情败类
感情败类 2020-11-28 02:29

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
10条回答
  •  不知归路
    2020-11-28 03:05

    The accepted answer will not return files prefix with a . To do that use

    for entry in "$search_dir"/* "$search_dir"/.[!.]* "$search_dir"/..?*
    do
      echo "$entry"
    done
    

提交回复
热议问题