[bash script]改进版目录和文件显示
#!/bin/bash
tab="\t"
pipe="|"
dash="--------"
fmt="$pipe${dash}"
lsallfile () {
for i in ${1}/*
do
if [ -f "$i" ]
then
echo -e "$fmt${i##*/}"
elif [ -d "$i" ]
then
echo -e "$fmt${i##*/}/"
fmt="$pipe$tab$fmt"
echo -e "${fmt%$dash}"
lsallfile ${i}
echo -e "${fmt%$dash}"
fmt=${fmt#"$pipe$tab"}
fi
done
}
if [ -z $1 ]
then
lsallfile .
else
lsallfile $1
fi
tab="\t"
pipe="|"
dash="--------"
fmt="$pipe${dash}"
lsallfile () {
for i in ${1}/*
do
if [ -f "$i" ]
then
echo -e "$fmt${i##*/}"
elif [ -d "$i" ]
then
echo -e "$fmt${i##*/}/"
fmt="$pipe$tab$fmt"
echo -e "${fmt%$dash}"
lsallfile ${i}
echo -e "${fmt%$dash}"
fmt=${fmt#"$pipe$tab"}
fi
done
}
if [ -z $1 ]
then
lsallfile .
else
lsallfile $1
fi