早教吧 育儿知识 作业答案 考试题库 百科 知识分享

linuxshell脚本编程问题,提示toomanyargumentsecho"enteradirectoryname:"readaif[–d$a–a–w$a]thenfilesdeleted=0filesremaining=0forcin`ls${a}`doecho"wishtodeletefile$c?"readansif[$ans='y']thenrm$a/$cfilesdel

题目详情
linux shell脚本编程问题,提示too many arguments
echo "enter a directory name:"
read a
if [ –d $a –a –w $a ]
then files_deleted=0
files_remaining=0
for c in `ls ${a}`
do
echo "wish to delete file $c?"
read ans
if [ $ans = 'y' ]
then
rm $a/$c
files_deleted=`expr $files_deleted + 1`
else
files_remaining=`expr $files_remaining + 1`
fi
done
echo "$files_deleted ordinary files deleted from the directory"
echo "$files_remaining ordinary files remaining in the directory"
else
echo "directory name entered is not a readable or writable directory"
fi
▼优质解答
答案和解析
估计是这个问题 [ -d $a -a -w $a ]
你这个逻辑是正确的,可能的问题就是有些字符可能有错,你在仔细检查下
另外可以根据报错信息定位