分页: 1 / 2
菜鸟求助
发表于 : 2007-03-20 16:13
由 baggio081
编了一个简单的shell脚本,然后执行的时候提示没找到命令.
文件名是rubbish,然后用./rubbish执行的.
怎么解决?
发表于 : 2007-03-20 16:27
由 xiehuoli
有没有给予执行权限
chmod 755 rubbinsh
脚本开始是怎么写的??
#!/bin/sh 调用sh程序执行 也可以调用bash执行
发表于 : 2007-03-20 16:44
由 baggio081
chmod +x rubbish 了
是还要设置环境变量吗?
发表于 : 2007-03-20 16:52
由 xiehuoli
#!/bin/sh 调用sh程序执行 也可以调用bash执行
开始调用sh程序执行
你脚本开头有没有这句?
要用sudo 执行哦
发表于 : 2007-03-20 17:50
由 baggio081
有#!/bin/sh 的..
sudo的话,就是直接
sudo ./rubbish 吗?
发表于 : 2007-03-20 17:55
由 xiehuoli
baggio081 写了:有#!/bin/sh 的..
sudo的话,就是直接
sudo ./rubbish 吗?
十分正确
真聪明
发表于 : 2007-03-30 8:28
由 zzyubuntu
是不是没在文件rubbish的当前目录!
发表于 : 2007-05-08 16:15
由 wkt
baggio081 写了:有#!/bin/sh 的..
sudo的话,就是直接
sudo ./rubbish 吗?
最好不要这样!
sh rubbish
bash rubbish
. ./rubbish #那是个点
都可以
如果用点的话 如果你的脚本里有个exit
很可能你会退出当前shell
只有你必须用root来运行时
用sudo ./rubbish 才比较好!!
发表于 : 2007-05-08 17:17
由 ztf
$#是不是$0?
发表于 : 2007-05-08 19:13
由 wkt
ztf 写了:$#是不是$0?
写个脚本 test.sh
代码: 全选
#!/bin/bash
echo "Hei,I am \$# and $# "
echo "Hei,I am \$0 and $0 "
$bash test.sh
这样不就知道了
发表于 : 2007-05-08 22:13
由 ztf
在bash脚本中,运行出现“不可预料的文件结尾”,但是打开源文件,那一行什么都么有。请问这是什么原因?
发表于 : 2007-05-08 23:38
由 5451vs5451
ztf 写了:在bash脚本中,运行出现“不可预料的文件结尾”,但是打开源文件,那一行什么都么有。请问这是什么原因?
类似这种情况
bash -c "if ["
bash: -c: line 1: syntax error: unexpected end of file
发表于 : 2007-05-10 17:47
由 ztf
#! /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的那两行
发表于 : 2007-05-10 21:56
由 thword
ztf 写了:$#是不是$0?
$#是指当前的参数个数
sed那行的意思是从第一行开始删除空行与空白行。
另,最好还是自己动手做试验一下。
发表于 : 2007-05-10 22:23
由 ztf
那个引号里的语法不懂,能说详细一点吗?整体的意思注释已经有了。