最近在做一些文本处理的工作,才对脚本的方便性有所体会。以下是一个获取一个目录下的所有文件名的脚本
#! /bin/bash
########################################################
# readfile.sh
# list the name of all file in the directory named by users
# copy right @Huyang
#########################################################
echo "please input the directory you want to traversal(遍历):"
read path
read_dir ()
{
for file in `ls $1`
do
#echo $1"/"$file
if [ -d $1"/"$file ]
then
read_dir $1"/"$file
else
echo $1"/"$file
fi
done
}
read_dir $path