What is the difference between `env` and `set`?

0290

The env and set commands are both used in the shell, but they serve different purposes and display different types of information:

env

  • Purpose: The env command is primarily used to display the environment variables for the current shell session.
  • Output: It lists only the environment variables, which are variables that are available to child processes. These variables typically include system settings and user-defined variables that are exported.
  • Usage: You can also use env to run a command in a modified environment.

Example:

env

set

  • Purpose: The set command is used to display all shell variables, including both environment variables and shell functions.
  • Output: It lists all variables (both local and global) defined in the current shell session, including shell options and functions.
  • Usage: It can also be used to set shell options and define variables.

Example:

set

Summary

  • Use env to see environment variables specifically.
  • Use set to see all shell variables and functions, including local variables.

0 Comments

no data
Be the first to share your comment!