您的位置:首页 > 编程语言 > PHP开发

测试php和mysql的链接是否成功php文件

2008-05-29 15:08 543 查看
上一篇因为没学会字符测试,所以写的文件数行脚本,运行起来并不是那么完美,看完0218-1课后,修改代码成如下,基本没有不理想的状态发现了:
#!/bin/bash
#
read -t 10 -p "Please enter a file path in 10 seconds:" fileName #超时设置成10秒
fileName=${fileName:-null} #变量默认值的设定
if [ "$fileName" == null ];then #字符测试的语句
echo -e "\033[31mTime out!Bad file name input.\033[0m" #这句写成了红色
exit 4 #自定义退出代码,可以随意
elif grep "^$" $fileName &> /dev/null;then
echo "$fileName has `grep -v "^$" $fileName | wc -l` lines and `grep "^$" $fileName | wc -l` space lines."
else
echo "$fileName has `grep -v "^$" $fileName | wc -l` lines and has no space line."
fi

这下算比较完美了,知识盲点会导致程序bug,呵呵。接下来还有文件测试的内容要学习。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: