LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 756|回复: 3

在redhat9里遇到一则bash脚本运行问题

[复制链接]
发表于 2005-8-15 05:41:59 | 显示全部楼层 |阅读模式
//mytar.sh -- a sample script:
#!/bin/bash

if [ "${1##*.}" = "tar" ]
then
        echo This appears to be a tarball.
else
        echo At first glance, this does not appear to be a tarball.
fi

然后给mytar.sh加上可执行属性:
$chmod 755 mytar.sh

运行该脚本:
$ ./mytar.sh thisfile.tar
提示出错:
./mytar.sh: line 3 : if [ tar = tar ]: command not found
./mytar.sh: line 4 : syntax error near unexpeced token `then'
./mytar.sh: line 4 : `then'

这个例子出自Daniel Robbins 的
《Bash by example, Part 1 Fundamental programming in the Bourne again shell (bash)》
http://www-106.ibm.com/developerworks/library/l-bash1.html
发表于 2005-8-15 07:12:43 | 显示全部楼层
这个例子看上去没有什么问题啊,是不是漏了空格什么的...
回复 支持 反对

使用道具 举报

发表于 2005-8-15 09:11:51 | 显示全部楼层
I think it should be "=="" not the "="
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-8-18 05:18:02 | 显示全部楼层
是我漏打了一个空格,多谢二楼的
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表