我需要一些帮助才能运行。只有两个部分。需要修复的两个bash函数
我是bash脚本编程的新手。我怎么重复这个,直到输入一个文件名? PS它似乎没有工作一段时间,直到我试过了。
ifSpaces(){
#if more than one file name if statement(checks for spaces)
if [ "$#" -eq "$(echo "[email protected]" | wc -w)" ]
then
echo -n "Please enter a filename: ";
read filename
else
echo -n "Please enter a single filename! ";
fi
}
这个函数应该测试文件是否可以写入。它似乎通过它,而不是测试它的权利。但我不确定。基本上,它有什么问题,请纠正,因为我没有得到它时,人们告诉我,而不是告诉我如何。
#how do I get this to work?
testFiles(){
#loop through files and test each one
for filename in "[email protected]"
do
filename="[email protected]"
# put this in a loop that grabs all the values.
# test all the file names
while [ -f "$filename" ]
do
if [ -w $filename ]
then
echo "The file exists and is writable";
overWriteFile
saveResults
elif [ -d $filename ]
then
read filename
echo "$filename";
echo "The file you specified exists and is a directory".
saveResults
else
>$directory$filename;
fi
done
echo "$filename";
echo "The file you specified exists and is neither a regular file nor a directory.";
done
saveResults
}
请在您的代码上使用缩进 - 它可以帮助人们对所写内容做出正面或反面的评论。 – 2010-12-06 01:51:16