Linux脚本的源代码和./执行之间的区别 [英] Difference between source and ./ execution of linux scripts

查看:116
本文介绍了Linux脚本的源代码和./执行之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

csh:

set a=0 
echo "a is $a"

当我执行./my_script.csh时,输出为:

when i do ./my_script.csh output is:

a is 

当我获取my_script.csh的源输出时:

when i do source my_script.csh output is:

a is 0 

为什么会这样.据我所知./执行使用新的shell.

Why is it so . As i know that ./ execution uses new shell.

推荐答案

检查当前外壳程序中是否设置了变量"a":

check if variable "a" is set in your current shell:

set | grep '^a='

请记住,一旦您向当前外壳程序获取脚本, 所有它的全局变量都存在,直到未设置或退出当前shell. 您可能需要启动一个新的shell,提供脚本,结束退出shell以执行有效的测试.

Remember that once you source script to your current shell, all it's global variables are there until unset or you exit the current shell. You may want to start a new shell, source the script, end exit shell to perform valid tests.

我不知道您遇到的问题的背景,但是您可能希望导出一些关键变量,以便在每个子流程中获得它们的副本.

I don't know the context of your problem, but you may want to export some key variables to have their copies in every subprocess.

这篇关于Linux脚本的源代码和./执行之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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