论坛首页 综合技术版 Linux

Shell if的问题

浏览 229 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
时间:2008-08-02 关键字: shell if
最近学习Shell,学习过程中出了点问题,一直找不到解决方案,所以在这里请各位给予帮助。先谢了!

delete.sh
1 #!/bin/sh
2
3 echo $1
4 if ["$1" -ne ""];then
5 cd . > $1
6 rm $1
7 else
8 echo "参数不能为空!"
9 exit
10 fi


root@test:~/workspace/shell# ls -l
总用量 12
-rwxr-xr-x 1 root root 109 2008-08-01 14:17 clean.sh
-rwxr-xr-x 1 root root 105 2008-08-02 18:16 delete.sh
-rw-r--r-- 1 root root 138 2008-08-02 18:09 exp1.sh

root@test:~/workspace/shell# ./delete.sh exp1.sh
exp1.sh
./delete.sh: 10: [exp1.sh: not found
参数不能为空!

出现这样的问题,不知是何解!
   
时间:2008-08-03
手头没有测试环境,但觉得文件测试应该使用-f
   
0 请登录后投票
时间:2008-08-04
我测试了下,发现是楼主[之后和]之前缺少空格。
注意,在[之后和]之前一定要有空格,以下代码可以正常运行。

echo $1
if [ "$1" -ne "" ];then
cd . > $1
rm $1
else
echo "12345"
exit
fi
   
0 请登录后投票
论坛首页 综合技术版 Linux

跳转论坛:
JavaEye推荐