Which of the following is the best way to list all defined shell variables?
A.
env
B.
set
C.
env -a
D.
echo $ENV
Explanation:
A) env – run a program in a modified environment (-a does not exist)
C) option -a does not exist
D) echo $ENV prints the shell variable $ENV if it exists
It’s A. not B. Typing env by itself lists all defined shell variables (Smith pg 423) and http://pubs.opengroup.org/onlinepubs/9699919799/utilities/env.html:
SYNOPSIS
env [-i] [name=value]… [utility [argument…]]
DESCRIPTION
The env utility shall obtain the current environment, modify it according to its arguments, then invoke the utility named by the utility operand with the modified environment.
Optional arguments shall be passed to utility.
If no utility operand is specified, the resulting environment shall be written to the standard output, with one name= value pair per line.
If the first argument is ‘-‘, the results are unspecified.
B is correct:
If no options or arguments are specified, set shall write the names and values of all shell variables in the collation sequence of the current locale. Each name shall start on a separate line, using the format:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_25_02
A and B are correct. env and set without arguments list all definde variables.
set: shows enviromet + shell variables (most complete)
env: shows only environment variables (+ used to alter vars. when executing a program)
Exactly!