LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2656|回复: 3

shell可以实现include功能吗?[已解决]

[复制链接]
发表于 2005-6-10 23:38:49 | 显示全部楼层 |阅读模式
我向写一个config.sh文件,里面放上各种配置信息。如下

  1. ip=192.168.0.10
  2. netmask=255.255.255.0
  3. hostname=serv1
  4. domain=test.com
复制代码


然后其它的脚本在最开始的地方可以先include这个些内容。
然后脚本里面就可以用$ip等变量获得这些信息了。

不知道能不能实现?
我看了看shell,没有include这个命令
有个.file好像是从文件读和执行。但我在shell里面些上.config.sh,总是报错。

还有就是,即使.file把config.sh当做shell来执行了,但是里面设置的变量也不能在调用它的脚本里面使用呀

各位兄弟帮我看看,怎末解决这个问题
发表于 2005-6-11 00:16:26 | 显示全部楼层
source filename [arguments]
              Read  and  execute  commands  from filename in the current shell
              environment and return the exit status of the last command  exe-
              cuted from filename.  If filename does not contain a slash, file
              names in PATH are used to find the  directory  containing  file-
              name.   The  file  searched  for in PATH need not be executable.
              When bash is  not  in  posix  mode,  the  current  directory  is
              searched  if no file is found in PATH.  If the sourcepath option
              to the shopt builtin command is turned  off,  the  PATH  is  not
              searched.   If any arguments are supplied, they become the posi-
              tional parameters when  filename  is  executed.   Otherwise  the
              positional  parameters  are unchanged.  The return status is the
              status of the last command exited within the  script  (0  if  no
              commands  are  executed),  and false if filename is not found or
              cannot be read.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-6-11 00:27:41 | 显示全部楼层
问题解决了。
多谢lastart兄弟。
这个source还真好用
回复 支持 反对

使用道具 举报

发表于 2005-6-11 11:03:06 | 显示全部楼层
. filename 也是一样的 . = source 命令
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表