当前位置: 技术问答>linux和unix
提问为什么程序提示出错,但还可以运行
来源: 互联网 发布时间:2016-07-08
本文导语: 程序如下 1 #!/bin/bash 2 #repiat question until user input correct answer. 3 echo -e "oralce backup program,this is savepath:/home/db_data/dmpbak/n" 4 read -p "please input save date(exp YYYYMMDD):" today ...
程序如下
1 #!/bin/bash
2 #repiat question until user input correct answer.
3 echo -e "oralce backup program,this is savepath:/home/db_data/dmpbak/n"
4 read -p "please input save date(exp YYYYMMDD):" today
5 name=$(find /tmp/ -name "$today"tmp".sh"| grep "$today"tmp"" )
6 if ["$name" eq ""]
7 then
8 vi $today"tmp"
9 else
10 echo -e "this is file is existence,please remove and run again"
11 exit
12 fi
13 cd /tmp/
运行结果如下
please input save date(exp YYYYMMDD):20091010
./tmp.sh: line 6: [/tmp/20091010tmp.sh: 没有那个文件或目录
this is file is existence,please remove and run again
因为为了测试,所以系统中有这个20091010tmp.sh这个文件,得出的结果是正确的,但为什么提示我的第6行出错呢?
我还编了个oralce 备份的脚本,请大家看看,有没有什么错误
#/bin/bash
#HISTORY: 2009-10-12
#
echo -e "oralce backup program,this is savepath:/home/db_data/dmpbak/n"
read -p "please input save date(exp YYYYMMDD):" today
su oralce
name=$(find /home/db_data/dmpbak/ -name "$today"_mis".dmp" )
if ["$name" eq ""]
then
exp sys/passwd@dbserver file=/home/db_data/dmpbak/$today"_mis".dmp owner=mis
else
echo -e "this is file is existence,please remove and run again"
exit
fi
exit
cd /home/db_date/dmpbak/
请大家指教
1 #!/bin/bash
2 #repiat question until user input correct answer.
3 echo -e "oralce backup program,this is savepath:/home/db_data/dmpbak/n"
4 read -p "please input save date(exp YYYYMMDD):" today
5 name=$(find /tmp/ -name "$today"tmp".sh"| grep "$today"tmp"" )
6 if ["$name" eq ""]
7 then
8 vi $today"tmp"
9 else
10 echo -e "this is file is existence,please remove and run again"
11 exit
12 fi
13 cd /tmp/
运行结果如下
please input save date(exp YYYYMMDD):20091010
./tmp.sh: line 6: [/tmp/20091010tmp.sh: 没有那个文件或目录
this is file is existence,please remove and run again
因为为了测试,所以系统中有这个20091010tmp.sh这个文件,得出的结果是正确的,但为什么提示我的第6行出错呢?
我还编了个oralce 备份的脚本,请大家看看,有没有什么错误
#/bin/bash
#HISTORY: 2009-10-12
#
echo -e "oralce backup program,this is savepath:/home/db_data/dmpbak/n"
read -p "please input save date(exp YYYYMMDD):" today
su oralce
name=$(find /home/db_data/dmpbak/ -name "$today"_mis".dmp" )
if ["$name" eq ""]
then
exp sys/passwd@dbserver file=/home/db_data/dmpbak/$today"_mis".dmp owner=mis
else
echo -e "this is file is existence,please remove and run again"
exit
fi
exit
cd /home/db_date/dmpbak/
请大家指教
|
我告诉你错误吧 中括号的地方缺少空格
if ["$name" eq ""]
改成 if [ "$name" eq "" ]
就不会报错了
第二个程序也一样
if ["$name" eq ""]
改成 if [ "$name" eq "" ]
就不会报错了
第二个程序也一样
|
同意二楼!
|
你可以用test -z 呀.
|
语法问题
与二楼一样 括号中间位置问题
if ["$name" eq ""]
convert to
if [ "$name" eq "" ]
与二楼一样 括号中间位置问题
if ["$name" eq ""]
convert to
if [ "$name" eq "" ]