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

查看:27
本文介绍了“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-local 变量,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 是一个独立的可执行文件;它只看到 shell 传递给它的变量或环境变量.

Since set is a built-in shell command, it also 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天全站免登陆