菜鸟求助

sh/bash/dash/ksh/zsh等Shell脚本
baggio081
帖子: 33
注册时间: 2006-11-27 20:13

菜鸟求助

#1

帖子 baggio081 » 2007-03-20 16:13

编了一个简单的shell脚本,然后执行的时候提示没找到命令.
文件名是rubbish,然后用./rubbish执行的.
怎么解决?
头像
xiehuoli
帖子: 5941
注册时间: 2006-06-10 8:43
来自: 中国 CS

#2

帖子 xiehuoli » 2007-03-20 16:27

有没有给予执行权限
chmod 755 rubbinsh
脚本开始是怎么写的??
#!/bin/sh 调用sh程序执行 也可以调用bash执行
年轻没有失败! ! ! ! ! !
噢!有怪兽,有怪兽!
baggio081
帖子: 33
注册时间: 2006-11-27 20:13

#3

帖子 baggio081 » 2007-03-20 16:44

chmod +x rubbish 了
是还要设置环境变量吗?
头像
xiehuoli
帖子: 5941
注册时间: 2006-06-10 8:43
来自: 中国 CS

#4

帖子 xiehuoli » 2007-03-20 16:52

#!/bin/sh 调用sh程序执行 也可以调用bash执行
开始调用sh程序执行
你脚本开头有没有这句?
要用sudo 执行哦
年轻没有失败! ! ! ! ! !
噢!有怪兽,有怪兽!
baggio081
帖子: 33
注册时间: 2006-11-27 20:13

#5

帖子 baggio081 » 2007-03-20 17:50

有#!/bin/sh 的..
sudo的话,就是直接
sudo ./rubbish 吗?
头像
xiehuoli
帖子: 5941
注册时间: 2006-06-10 8:43
来自: 中国 CS

#6

帖子 xiehuoli » 2007-03-20 17:55

baggio081 写了:有#!/bin/sh 的..
sudo的话,就是直接
sudo ./rubbish 吗?
十分正确
真聪明
年轻没有失败! ! ! ! ! !
噢!有怪兽,有怪兽!
头像
zzyubuntu
帖子: 55
注册时间: 2006-12-09 19:22

#7

帖子 zzyubuntu » 2007-03-30 8:28

是不是没在文件rubbish的当前目录!
wkt
帖子: 849
注册时间: 2006-09-07 22:51
联系:

#8

帖子 wkt » 2007-05-08 16:15

baggio081 写了:有#!/bin/sh 的..
sudo的话,就是直接
sudo ./rubbish 吗?
最好不要这样!
sh rubbish
bash rubbish
. ./rubbish #那是个点
都可以
如果用点的话 如果你的脚本里有个exit
很可能你会退出当前shell
只有你必须用root来运行时
用sudo ./rubbish 才比较好!!
ztf
帖子: 44
注册时间: 2007-04-29 13:15

#9

帖子 ztf » 2007-05-08 17:17

$#是不是$0?
wkt
帖子: 849
注册时间: 2006-09-07 22:51
联系:

#10

帖子 wkt » 2007-05-08 19:13

ztf 写了:$#是不是$0?
写个脚本 test.sh

代码: 全选

#!/bin/bash
echo "Hei,I am \$# and $# "
echo "Hei,I am \$0 and $0  "
$bash test.sh
这样不就知道了
ztf
帖子: 44
注册时间: 2007-04-29 13:15

#11

帖子 ztf » 2007-05-08 22:13

在bash脚本中,运行出现“不可预料的文件结尾”,但是打开源文件,那一行什么都么有。请问这是什么原因?
头像
5451vs5451
帖子: 345
注册时间: 2006-07-14 18:56
来自: Apple Valley, Planet Tux, Linux System

#12

帖子 5451vs5451 » 2007-05-08 23:38

ztf 写了:在bash脚本中,运行出现“不可预料的文件结尾”,但是打开源文件,那一行什么都么有。请问这是什么原因?
类似这种情况
bash -c "if ["
bash: -c: line 1: syntax error: unexpected end of file
ztf
帖子: 44
注册时间: 2007-04-29 13:15

#13

帖子 ztf » 2007-05-10 17:47

#! /bin/sh
# Strips off the header from a mail/News message i.e. till the first
# empty line
# Mark Moraes, University of Toronto

# ==> These comments added by author of this document.

if [ $# -eq 0 ]; then
# ==> If no command line args present, then works on file redirected to stdin.
sed -e '1,/^$/d' -e '/^[ ]*$/d'
# --> Delete empty lines and all lines until
# --> first one beginning with white space.
else
# ==> If command line args present, then work on files named.
for i do
sed -e '1,/^$/d' -e '/^[ ]*$/d' $i
# --> Ditto, as above.
done
fi

# ==> Exercise: Add error checking and other options.
# ==>
# ==> Note that the small sed script repeats, except for the arg passed.
# ==> Does it make sense to embed it in a function? Why or why not?
请好心人解析一下sed的那两行
thword
帖子: 119
注册时间: 2007-04-09 12:19

#14

帖子 thword » 2007-05-10 21:56

ztf 写了:$#是不是$0?
$#是指当前的参数个数

sed那行的意思是从第一行开始删除空行与空白行。

另,最好还是自己动手做试验一下。
ztf
帖子: 44
注册时间: 2007-04-29 13:15

#15

帖子 ztf » 2007-05-10 22:23

那个引号里的语法不懂,能说详细一点吗?整体的意思注释已经有了。
回复