如何从另一个shell脚本中调用shell脚本? [英] How to call shell script from another shell script?

查看:318
本文介绍了如何从另一个shell脚本中调用shell脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请提供样品code从另一个Bash脚本中运行一个猛砸脚本

Please provide sample code to run a Bash script from within another Bash script.

推荐答案

有几个方法可以做到这一点:

There are a couple of ways you can do this:


  1. 首先是使其他可执行脚本,在顶部添加#!/斌/庆典行,文件所在的路径在$ PATH环境变量。然后,你可以把它作为一个正常的命令。

  1. The first is to make the other script executable, add the #!/bin/bash line at the top, and the path where the file is to the $PATH environment variable. Then you can call it as a normal command.

来源称它命令(别名是 )。像这样:源/路径/到/脚本

Call it with the source command (alias is .) like this: source /path/to/script.

使用庆典命令来执行它: /斌/庆典/路径/到/脚本

第一和第三个方法执行脚本作为另一种方法,这样的变量和函数在其他脚本将无法访问。第二种方法将执行第一脚本处理脚本,并从其他脚本变量和函数拉,使他们从调用脚本使用。

The first and third methods execute the script as another process, so variables and functions in the other script will not be accessible. The second method executes the script in the first scripts process, and pulls in variables and functions from the other script so they are usable from the calling script.

这篇关于如何从另一个shell脚本中调用shell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆