difference between sourcing / running / execing

本文介绍了三种执行Shell脚本的方法:创建新Shell并运行脚本、在当前Shell中执行脚本以及使用exec命令替换当前Shell进程。每种方法对环境变量的影响不同。

./script creates a new shell and executes each command in the script within the new shell. When the end of the script file is encountered, the new shell exits. Any changes in the new shell caused by the script are lost when the shell exits.

For example, if the file
/home/user/sample/script/test contains...

cd /usr/games
pwd
echo hi

Then the command sequence would yield the following output:

prompt>cd /home/user/sample/script
prompt>pwd
/home/user/sample/script
prompt>chmod +x test
prompt>./test
/usr/games
hi
prompt>pwd
/home/user/sample/script

source Execution
source execute a shell script within the context of the current shell. Since execution takes place within the context of the current shell, any changes in the shell are retained following the completion of the shell.
Example:

prompt>cd /home/user/sample/script
prompt>pwd
/home/user/sample/script
prompt>source test
/usr/games
hi
prompt>pwd
/usr/games


Execing a <command> (ie. shell script or executable) means give exec <command> on the shell prompt.

The exec command will execute a command in place of the current shell, that is, it terminates the current shell and starts a new process in its place.

exec was often used to execute the last command of a shell script. This would kill the shell slightly earlier; otherwise, the shell would wait until the last command was finished. This practice saves a process and some memory.

try exec ls. you will be logged out from your login shell.

exec also manipulates file descriptors in the Bourne shell.
$exec >>logoutput
after issuing this command you will not see output of any command in your console. all output goes into logoutput file.

use exec >/dev/console to return.

$exec 2>errs.out
means that from then on, stderr goes into errs.out file


Tom's summary

1) ./set-env.sh --> start new shell, run it, the new shell exits.  --> Env variables not set in the current shell.

2) source ./set-env.sh --> run it the current shell. --> Env variables are set in the current shell.

3) exec ./set-env.sh --> terminate the current shell, start new shell, run it. --> Maybe you just log off immediately.

 

 

内容概要:本文围绕VMware虚拟化环境在毕业设计中的应用,重点探讨其在网络安全与AI模型训练两大领域的实践价值。通过搭建高度隔离、可复现的虚拟化环境,解决传统物理机实验中存在的环境配置复杂、攻击场景难还原、GPU资源难以高效利用等问题。文章详细介绍了嵌套虚拟化、GPU直通(passthrough)、虚拟防火墙等核心技术,并结合具体场景提供实战操作流程与代码示例,包括SQL注入攻防实验中基于vSwitch端口镜像的流量捕获,以及PyTorch分布式训练中通过GPU直通实现接近物理机性能的模型训练效果。同时展望了智能化实验编排、边缘虚拟化和绿色计算等未来发展方向。; 适合人群:计算机相关专业本科高年级学生或研究生,具备一定虚拟化基础、网络安全或人工智能背景,正在进行或计划开展相关方向毕业设计的研究者;; 使用场景及目标:①构建可控的网络安全实验环境,实现攻击流量精准捕获与WAF防护验证;②在虚拟机中高效开展AI模型训练,充分利用GPU资源并评估性能损耗;③掌握VMware ESXi命令行与vSphere平台协同配置的关键技能; 阅读建议:建议读者结合VMware实验平台动手实践文中提供的esxcli命令与网络拓扑配置,重点关注GPU直通的硬件前提条件与端口镜像的混杂模式设置,同时可延伸探索自动化脚本编写与能效优化策略。
目录: 1、【coze自动化]基础和建立一个简单的机器人实操(2024).mp4 2、【coze自动化]实操案例用插件和工作流-提取文案1(做好.mp4 3、【coze自动化]实操案例用大模型+插件+工作流-提取文案2.mp4 4、【coze自动化]实操案例用2个大模型+插件+工作流-提取文案3.mp4 5、【coze自动化]实操案例完结-2大模型+4插件+工作流-提取文案4.mp4 6、【扣子coze插件篇,-探索和测试插件的系统方法1].mp4 7、【扣子Coze自动化]案例实操-文本转脑图1.mp4 8、【扣子Coze自动化]如何写工作流的代码?普通人就能搞定--简单实用.mp4 9、【扣子Coze自动化]实操案例--选择器的落地应用-判断链接还是文本,mp4 10、【扣子Coze自动化]选择器分支和代码联合高级应用-让工作流更灵活应对多种场景.mp4 11、【扣子Coze自动化]如何把机器人发布平台.mp4 12_【AI案例篇]coze工作流处理1万字长文本和详细操作思路和方法.mp4 13、【扣子Coze自动化]一天500条文案详细思路--引入自定义插件.mp4 14、【扣子Coze自动化]万能自定义扣子插件--小白也能轻松搞定代码逻辑18:08.mp4 15、【扣子Coze自动化]获取官方apikey和测试自定义插件.mp4 16、【扣子Coze自动化]coze批处理,一次提炼、润色100条小爆款文案-标题-配音.mp4 17、【附加高级篇-来线下过度]3分钟提炼近百条视频文案介绍-(1).mp4 18、【附加高级篇-来线下过度]实战-3分钟提炼近百条视频文案.mp4 19、【扣子Coze附加高级篇-来线下过度】完结升级润色提炼爆款标题-3分钟提近百条文案 ............... 网盘文件永久链接
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值