代码:
#/bin/bash
#测试递归目录
#Auter:panda
#Time:2011-08-03
declare -i i
i=1
user="/home"
#fname=`echo ${PWD} | sed "s/$DIR//g"` sed方法
#fname=`echo $PWD |awk -F/ 'OFS="/"{print $1,$2,$3}'` awk方法
DIR=`echo ${PWD} | awk -F/ '{print $NF}' `
fname=`echo ${PWD}`
for (( ; $i ; ))
do
echo " $DIR 目录下的文件是:"
cd $fname
for f in $(ls $fname)
do
echo $f
done
fname=`echo ${PWD} | sed -e "s/\/$DIR$//g"`
# echo $fname
DIR=`echo $fname | awk -F/ '{print $NF}' `
# echo $DIR
if [ "$fname" != $user ] ;then
i=1
else
i=0
fi
done
运行结果:
panda@panda-pc:~/Code/Shell/Change_the_name/llll/ccc/pwe/pwe$ ./cd_ls.sh
pwe 目录下的文件是:
cd_ls.sh
pwe 目录下的文件是:
cd_ls.sh
change_digui.sh
change.sh
pwe
wang
Wqe
ccc 目录下的文件是:
pwe
wang
wangp
llll 目录下的文件是:
ccc
ppp
Change_the_name 目录下的文件是:
change1
change.sh
data
llll
Qoiuy
Qwweer
Wang
Wangpan
Shell 目录下的文件是:
case_test1.sh
case_test2.sh
case_test.sh
Change_the_name
chang_suffix.sh
data
data_abc.sh
data_awk.sh
datas
eq.sh
Fburaqie_old.sh
Fburaqie.sh
for_test1.sh
for_test2.sh
for_test3.sh
for_test4.sh
for_test5.sh
for_test6.sh
for_test.sh
hello.c
if_test1.sh
if_test2.sh
if_test.sh
Interview_questions
kernel_reader
nihao_sed
nihao_sed.sh
pswd
pswdo
rename
variable12.sh
variable1.sh
Code 目录下的文件是:
c
linux
linuxos
Perl
Shell
panda 目录下的文件是:
Code
Desktop
Documents
Downloads
EIOffice
Kernel
Music
Pictures
Public
Software
Study
Templates
tmp
Ubuntu
One
Videos
panda@panda-pc:~/Code/Shell/Change_the_name/llll/ccc/pwe/pwe$
该程序 有许多的不足,望指教
阅读(1053) | 评论(2) | 转发(0) |