I recently got a book on shell scripting in bash. It states to list all the Environment Variables using the printenv command. I've noticed though that this doesn't list all variables, for example $PWD or $REPLY or $SSH_TTY. Is their a complete list I can reference for all of these Environment Variables and their Functions?
2 Answers
To display a list of the Environment Variables you can use
printenv # or set to show also shell environment vars thanks @gordon set #if you want to see it nicely you can pipe it to more like this printenv | more set | more 3 Comments
set will show both shell and environment variables, without distinguishing which are which.set is certainly useful, and we should point out that it additionally lists the functions as well.declare -p to list all shell variable.Within a shell like bash there are two types of variables; environment variables (Wikipedia) and shell variables. There are a number of predefined shell variables.
You can use the export built-in to "promote" a shell variable to an environment variable, which has the effect of making that variable available to any subprocesses launched from the shell.
As the name implies, printenv only reports the process' environment variables. Variables like PWD or REPLY are shell variables, and thus aren't displayed. As suggested in the comments, invoking set with no arguments will print all variables (environment and shell) available in your current session.
$REPLYis a builtin variable from the shell not environment. for your question trydeclare -xsetcommand might do what you want.setanddeclare -xseem to be working for me. Thank Youprintenvwill show all the environment variables that are set in your current shell. It doesn't show all that could be set (you can technically set almost any string as an environment variable). There are a large number that will be set under certain circumstances (e.g. in an ssh session); or that, if set, would have a special function (e.g. theLANGandLC_*variables, which would tell programs what locale to use; seeman locale). There are no full lists of those, because anyone who writes a program can make it create/react to any variable they want, thus creating a new one.