荷兰校友的作业-2

a) Write a script IsFilePresent which expects one parameter.
When a file is present in the current directory its output is:”File is present.” Else it’s output is: File is nto present.
Make sure the script gives a useful error if one or two or more parameters are given.
b) change the script from 4.a) so it will accept any number of parameters. (Hint: find information on the shift command).
c) Make the script of assignemnt4 b) interactively. So it will ask for a file name, state the presents of that file and ask if you want to type another filename or not.
If yes it asks for a new file name. Quit when “stop” is given as filename.


我的答案:(只给针对最复杂的C的,A和B只是C的精简版,这里就不给出来了,答案不是最优化的,因为深夜脑子发木,凑合实现了而已)
#!/usr/local/bin/bash
echo “Please give me a filename, I’ll check if it is present or not. Use stop to quit.”
while read FILENAME
do
if test “$FILENAME” != “stop”
then
if test -e $FILENAME
then
echo File $FILENAME is present.
else
echo File $FILENAME is not present.
fi
echo “Do you want to type another filename or not (yes/stop)?”
while read IFSTOP
do
if test “$IFSTOP” != “yes”
then
if test “$IFSTOP” != “stop”
then
echo “please choose yes or stop.”
continue;
else
exit;
fi
else
echo “please input filename you want to check:”
break;
fi
done
else
break;
fi
done
挺累的……sigh….睡觉了。。script编程还是很有用处的……

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据