Chinaunix

标题: 初学SHELL,一句看不懂... [打印本页]

作者: THEBEST    时间: 2006-01-18 10:26
标题: 初学SHELL,一句看不懂...
  1. ps -ef |grep -v grep| grep  "^$2" |grep $1 >/dev/null
复制代码
这一句是在一个函数中的.
如函数名为_start_process;我知道$1 $2是传给函数的第一和第二个参数.

请问传参数调用是直接
  1. _start_process a; b
复制代码
这样吗?中间要有;号?我看的书上<<LINUX与UNIX Shell编程指南>>没仔细讲这个.
作者: waitwill    时间: 2006-01-18 10:43
分号是分割命令的
作者: THEBEST    时间: 2006-01-18 10:48
原帖由 waitwill 于 2006-1-18 10:43 发表
分号是分割命令的

那其它的呢?如何传多个参数给函数来调用?
那句是什么意思?
作者: waitwill    时间: 2006-01-18 10:50
_start_process a b
这样就传了两个参数
如果说得不对,还请谅解,我也是菜鸟
作者: THEBEST    时间: 2006-01-18 10:56
我知道那句shell是什么意思了.只是对函数参数的传递还不大了解.
作者: waitwill    时间: 2006-01-18 10:58
这个市函数?
我理解成shell脚本了
作者: 寂寞烈火    时间: 2006-01-18 11:42
原帖由 THEBEST 于 2006-1-18 10:26 发表
  1. ps -ef |grep -v grep| grep  "^$2" |grep $1 >/dev/null
复制代码
这一句是在一个函数中的.
如函数名为_start_process;我知道$1 $2是传给函数的第一和第二个参数.

请问传参数调用是直接[cod ...

a就是$1
b就是$2
应该是这样的吧
_start_process a b

to 楼上:
函数就是一个用来重复执行的语句块,在shell里,你可以把脚本写成函数,因为函数(shell里的)本身就是一个脚本

[ 本帖最后由 寂寞烈火 于 2006-1-18 11:44 编辑 ]
作者: ruifox    时间: 2006-01-18 17:59
正确的写法应该是
_start_process a b
a和b分别代表第1个和第2个参数
另外shell中的函数一点也不神秘,只不过是用{}括起来,可以接收参数,可以
重复调用的一串命令而已。
ps -ef |grep -v grep| grep  "^$2" |grep $1 >/dev/null
这个函数写得实在有点问题,
>前面表示检查系统进程中含有a或b的进程情况,但>/dev/null表示
结果不输出,相当什么也不做,莫名其妙!
作者: dradhzn    时间: 2006-01-18 21:21
原帖由 ruifox 于 2006-1-18 17:59 发表
结果不输出,相当什么也不做,莫名其妙!


guess the next command could be  
if [ $? -eq 1 ]
or
if [ $? -eq 0 ]

you are right all the way down until the last statment
">/dev/null" turns the stdout off so that there is no stdout on screen since the stdout doesn't make sense here , but the "$?" does make sense to the next command .

[ 本帖最后由 dradhzn 于 2006-1-18 21:31 编辑 ]




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2