First, you must understand that environment variables
and shell variables
are not the same thing.
Then, you should know that shells have attributes
which govern how it works. These attributes are not environment nor shell variables.
Now, on to answering your question.
env
: without any options, shows current environment variables with their values; However can be used to set environment variable for a single command with the -i flagset
: without options, the name and value of each shell variable are displayed* ~ from running man set in rhel; can also be used to set shell attribute. This command DOES NOT set environment nor shell variable.declare
: without any options, the same as env; can also be used to set shell variableexport
: makes shell variables environment variables
In short:
set
doesn’t set shell nor environment variables. 例如:set -eenv
can set environment variables for a single command. 直接设置环境变量,不能将shell vairables
导出成environment variable
declare
sets shell variables. 例如:declare -a s='hello shell'
export
makes shell variables environment variables. 例如:可以直接将shell vairables
导出成environment variable
,export s