各位请进,变量的累加效应在那体现
有这样一段shell代码,perm变量的累加效应在哪里体现?也就是说, perm变量为何每次都可以在前面内容的基础上再加上后面的内容呢,例如,当前是内容"readable",运行完后两句后内容是“readable execuable”
read -p "Please input a directory:" dir
if [ "$dir" == "" ] || [ ! -d "$dir" ] ; then
echo -e "The $dir is not existed in system"; exit 1
fi
filelist=`ls $dir`
for filename in $filelist
do
perm=""
test -r "$dir/$filename" && perm="$perm readable"
test -w "$dir/$filename" && perm="$perm writable"
test -x "$dir/$filename" && perm="$perm execuable"
echo "The files in $dir/$filename is $perm"
done
运行结果如下:
...
The files in /sbin/ureadahead is readable execuable
The files in /sbin/wipefs is readable execuable
The files in /sbin/wpa_action is readable execuable
The files in /sbin/wpa_cli is readable execuable
The files in /sbin/wpa_supplicant is readable execuable
The files in /sbin/xtables-multi is readable execuable