Which of the following is the best way to list all defined shell variables?

Which of the following is the best way to list all defined shell variables?

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



Leave a Reply 5

Your email address will not be published. Required fields are marked *


Chris C

Chris C

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.

manuel

manuel

A and B are correct. env and set without arguments list all definde variables.

Paco

Paco

set: shows enviromet + shell variables (most complete)
env: shows only environment variables (+ used to alter vars. when executing a program)