[Bash] Environment variables

Environment variables are defined by the shell and shell scripts.

To list the current environment variables, type export:

~ $ export
declare -x DISPLAY=":0"
declare -x HOME="/home/substack"
declare -x HUSHLOGIN="FALSE"
declare -x LANG="en_US.UTF-8"
declare -x LD_LIBRARY_PATH="/home/substack/prefix/lib:/usr/local/lib:/usr/lib/x86_64-linux-gnu:/usr/lib:/lib64:/lib"
declare -x LIBGL_DRIVERS_PATH="/usr/lib/i386-linux-gnu/dri:/usr/lib/x86_64-linux-gnu/dri"
declare -x LOGNAME="substack"
declare -x MAIL="/var/mail/substack"
declare -x OLDPWD="/home/substack/projects/workshops"
declare -x PATH="/home/substack/prefix/bin:/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin:/usr/local/games:/usr/games"
declare -x PREFIX="/home/substack/prefix"
declare -x PWD="/home/substack"
declare -x ROXTERM_ID="0x43962f0"
declare -x ROXTERM_NUM="15"
declare -x ROXTERM_PID="2521"
declare -x SHELL="/bin/bash"
declare -x SHLVL="3"
declare -x TERM="xterm"
declare -x USER="substack"
declare -x WINDOWID="8684328"
declare -x WINDOWPATH="7"
declare -x XAUTHORITY="/home/substack/.Xauthority"

You can use any environment variable by refering to its $NAME.

For example to print the value of $HOME do:

~ $ echo $HOME
/home/substack

You can use environment variables in any command:

~ $ ls /home/$USER
doc  media  notes.txt  projects

To define your own environment variable, just put its name followed by an equal sign (with no spaces) followed by its value:

~ $ ANIMAL=cats
~ $ echo $ANIMAL
cats

Define env variables like this only exists for the current bash session, if you open a child node process, env variable won't be there.

If you want it to be avaiable for child process, you can use export

~ $ export ANIMAL=cats
~ $ node
~ $ process.env.ANIMAL
~ $ cat
posted @   Zhentiw  阅读(8)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2020-06-10 [CSS3] CSS Selector
2019-06-10 [Web Component] Allow External Styling of a Web Component's Shadow DOM
2016-06-10 [TypeScript] Understanding Decorators
2016-06-10 [TypeScript] Using Typings and Loading From node_modules
2016-06-10 [TypeScript] Using Lodash in TypeScript with Typings and SystemJS
2016-06-10 [TypeScript ] What Happens to Compiled Interfaces
点击右上角即可分享
微信分享提示