"env"和"env"之间有什么区别和“设置" (在Mac OS X或Linux上)? [英] What's the difference between "env" and "set" (on Mac OS X or Linux)?

查看:318
本文介绍了"env"和"env"之间有什么区别和“设置" (在Mac OS X或Linux上)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行"env"和"set"时,我得到类似的结果. Set提供了更多结果-它是env的超集吗?

I get similar results running "env" and "set". Set gives more results - is it a superset of env?

set的手册页未提供任何信息.这些命令如何工作,有什么区别?

The man page for set doesn't give any information. How do these commands work and what's the difference?

推荐答案

长话短说:set可以看到shell局部变量,env不能.

Long story short: set can see shell-local variables, env cannot.

Shell可以具有2种类型的变量:只能从当前shell访问的局部变量,以及(导出的)环境变量,这些变量将传递给每个已执行的程序.

Shells can have variables of 2 types: locals, which are only accessible from the current shell, and (exported) environment variables, which are passed on to every executed program.

由于set内置 shell命令,因此它也可以看到shell局部变量(包括shell函数).另一方面,env是一个独立的可执行文件;它只会看到外壳传递给它的变量或环境变量.

Since set is a built-in shell command, it also sees sees shell-local variables (including shell functions). env on the other hand is an independent executable; it only sees the variables that the shell passes to it, or environment variables.

当您键入a=1之类的行时,将创建一个局部变量(除非该变量已在环境中存在).环境变量是使用export a=1

When you type a line like a=1 then a local variable is created (unless it already existed in the environment). Environment variables are created with export a=1

这篇关于"env"和"env"之间有什么区别和“设置" (在Mac OS X或Linux上)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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