[shell script]脚本实现目录和文件名显示
#!/bin/bash
inc=""
tab="\t"
lsallfile () {
for i in ${1}/*
do
echo -e "$inc${i##*/}"
if [ -d "$i" ]
then
inc="$inc$tab"
echo ""
lsallfile "${i}"
echo ""
inc=${inc#"$tab"}
fi
done
}
if [ -z $1 ]
then
lsallfile .
else
lsallfile $1
fi
inc=""
tab="\t"
lsallfile () {
for i in ${1}/*
do
echo -e "$inc${i##*/}"
if [ -d "$i" ]
then
inc="$inc$tab"
echo ""
lsallfile "${i}"
echo ""
inc=${inc#"$tab"}
fi
done
}
if [ -z $1 ]
then
lsallfile .
else
lsallfile $1
fi