Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
482 views
in Technique[技术] by (71.8m points)

linux - Difference between shell and environment variables

What are the differences between shell and environment variables? Where are these variables stored?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Citing this source,

Standard UNIX variables are split into two categories, environment variables and shell variables. In broad terms, shell variables apply only to the current instance of the shell and are used to set short-term working conditions; environment variables have a farther reaching significance, and those set at login are valid for the duration of the session. By convention, environment variables have UPPER CASE and shell variables have lower case names.

To list all environment variables, use printenv and to list all shell variables, use set.

You'll note that the environment variables store more permanent value, e.g.:

HOME=/home/adam

Which changes quite seldom, while the shell variables stores local, temporary, shell-specific values, e.g.:

PWD=/tmp

which changes every time you change your current directory.

For most practical tasks, set environment values by adding export VARIABLE_NAME=VALUE to your ~/.bashrc file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...