[Bash] env

Commands:

export: Set environment variables.
env: View environment variables.
echo: Display environment variables.
Common Environment Variables:

PATH: Directories where the shell looks for executable files.
HOME: User's home directory.
USER: Current logged-in user.

Setting Environment Variables:

export VARIABLE_NAME=value

Example:

export MY_VAR="Hello World"

Viewing Environment Variables:

env

Displaying Environment Variables:

echo $VARIABLE_NAME

Pratice

echo 'export FOO="bar"' > envscript.sh
echo 'echo $FOO' >> envscript.sh
chmod +x envscript.sh
./envscript.sh

# Do in one line
export USER_NAME="Alice"; echo $USER_NAME
posted @ 2024-05-19 15:48  Zhentiw  阅读(6)  评论(0编辑  收藏  举报