分页: 1 / 1

急需高手帮忙指点下简单脚本调用问题

发表于 : 2012-04-02 10:47
brucehe
该脚本如下:
#!/bin/bash
# father script.
echo "this is the father"
FILM="A Few Good Men"
echo "I like the film :$FILM"
# call the child script
# but export variable first
export FILM
child
echo "back to father"
echo "and the film is :$FILM"
调用的“child”脚本如下:
#!/bin/bash
# child
echo "called from father..i am child"
echo "film name is :$FILM"
FILM="Die Hard"
echo "changing film to :$FILM"
|运行father脚本不能调用child脚本,具体问题为”./father:9:child: not found"。
希望能得到高手指点,菜鸟非常感谢。

Re: 急需高手帮忙指点下简单脚本调用问题

发表于 : 2012-04-02 10:57
枫叶饭团

代码: 全选

[maplebeats@maplebeats bash]$ cat father 
#!/bin/bash
# father script.
echo "this is the father"
FILM="A Few Good Men"
echo "I like the film :$FILM"
# call the child script
# but export variable first
export FILM
./child
echo "back to father"
echo "and the film is :$FILM"
[maplebeats@maplebeats bash]$ sh father
this is the father
I like the film :A Few Good Men
called from father..i am child
film name is :A Few Good Men
changing film to :Die Hard
back to father
and the film is :A Few Good Men
[maplebeats@maplebeats bash]$ 

Re: 急需高手帮忙指点下简单脚本调用问题

发表于 : 2012-04-02 11:00
redhatlinux10
brucehe 写了:该脚本如下:
#!/bin/bash
# father script.
echo "this is the father"
FILM="A Few Good Men"
echo "I like the film :$FILM"
# call the child script
# but export variable first
export FILM
child
echo "back to father"
echo "and the film is :$FILM"
调用的“child”脚本如下:
#!/bin/bash
# child
echo "called from father..i am child"
echo "film name is :$FILM"
FILM="Die Hard"
echo "changing film to :$FILM"
|运行father脚本不能调用child脚本,具体问题为”./father:9:child: not found"。
希望能得到高手指点,菜鸟非常感谢。
你调用child脚本时,不应该是

代码: 全选

child
而应该是

代码: 全选

source /path/to/child.sh
第一种用法是用于调用函数的。

Re: 急需高手帮忙指点下简单脚本调用问题

发表于 : 2012-04-02 11:05
cao627
安全原因 shell PATH变量中 没有./ 所以不会在当前目录查找命令
:em11

Re: 急需高手帮忙指点下简单脚本调用问题

发表于 : 2012-04-02 11:19
brucehe
谢谢枫叶饭团帮忙解决了该问题。谢谢

Re: 急需高手帮忙指点下简单脚本调用问题

发表于 : 2012-04-02 12:32
hoxily
学习了. :em01