QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 914|回复: 2

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

[复制链接]
发表于 2005-8-15 03:55:39 | 显示全部楼层 |阅读模式
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 09:53:38 | 显示全部楼层
在我这里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]
回复

使用道具 举报

发表于 2005-8-15 09:55:42 | 显示全部楼层
你可以试试在then前加个";"
回复

使用道具 举报

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

本版积分规则

GMT+8, 2024-10-4 16:48 , Processed in 0.043988 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

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