[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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源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