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

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

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
在我这里no problem!
[code:1][root@cold ~]# cat tmp
#!/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
[root@cold ~]# ./tmp thisfile.tar
This appears to be a tarball.[/code:1]
你可以试试在then前加个";"