当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 6 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : 急需高手帮忙指点下简单脚本调用问题
帖子发表于 : 2012-04-02 10:47 

注册: 2011-09-27 22:47
帖子: 7
送出感谢: 0 次
接收感谢: 0 次
该脚本如下:
#!/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"。
希望能得到高手指点,菜鸟非常感谢。


页首
 用户资料  
 
2 楼 
 文章标题 : Re: 急需高手帮忙指点下简单脚本调用问题
帖子发表于 : 2012-04-02 10:57 
头像

注册: 2010-06-16 1:05
帖子: 14668
地址: Tencent
系统: Mac OS X
送出感谢: 1
接收感谢: 153
代码:
[[email protected] 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"
[[email protected] 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
[[email protected] bash]$


_________________
twitter求fo:http://twitter.com/maplebeats
博客求踩:http://maplebeats.com


页首
 用户资料  
 
3 楼 
 文章标题 : Re: 急需高手帮忙指点下简单脚本调用问题
帖子发表于 : 2012-04-02 11:00 
头像

注册: 2008-01-22 23:24
帖子: 773
地址: 三亚
送出感谢: 1
接收感谢: 15
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

第一种用法是用于调用函数的。


_________________
牛牛博客
linux 系统中 Chrome 地址栏输入卡顿的解决方法
Linux 下 MPV 和 VLC 播放器 VAAPI 显卡加速对比
---
using : openSUSE 13.2 ( 3.16.6-2 x86_64 ) , KDE 4.14.2


页首
 用户资料  
 
4 楼 
 文章标题 : Re: 急需高手帮忙指点下简单脚本调用问题
帖子发表于 : 2012-04-02 11:05 

注册: 2007-12-05 10:57
帖子: 1003
地址: 金山
系统: ubuntu14.04
送出感谢: 13
接收感谢: 62
安全原因 shell PATH变量中 没有./ 所以不会在当前目录查找命令
:em11


页首
 用户资料  
 
5 楼 
 文章标题 : Re: 急需高手帮忙指点下简单脚本调用问题
帖子发表于 : 2012-04-02 11:19 

注册: 2011-09-27 22:47
帖子: 7
送出感谢: 0 次
接收感谢: 0 次
谢谢枫叶饭团帮忙解决了该问题。谢谢


页首
 用户资料  
 
6 楼 
 文章标题 : Re: 急需高手帮忙指点下简单脚本调用问题
帖子发表于 : 2012-04-02 12:32 
头像

注册: 2011-02-11 21:10
帖子: 46
送出感谢: 0 次
接收感谢: 2
学习了. :em01


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 6 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 1 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译