目录
Environment Variables
Environment variables are like our own variables, but they are defined for us by the system, allowing us to know things about our script’s environment.
A small list of Environment Variables:
HOME
: user’s home directoryPATH
: directories which are searched for commandsHOSTNAME
: hostname of the machineSHELL
: shell that is being usedUSER
: user of this sessionTERM
: type of command-line terminal that is being used
An example
You may change the content of the environment variables and then use them in your own script. However, those changes are not global and thus are temporary. Environment variables will revert to the way that they were set after that.
#!/usr/bin/env bash
echo "The PATH is: $PATH"
echo "The TERMINAL is: $TERM"
if [ -z $EDITOR]
then
echo "The EDITOR var is not set"
fi
PATH="/some_path"
echo "The PATH is: $PATH"
# The PATH will revert to the way that they were set before your script run.
exit 0
References
LinkedIn Learning: https://www.linkedin.com/learning/learning-linux-shell-scripting-2018