env's Examples

access all environment variables and the values associated with them we give env command without any option

$ env

all the line are displayed without any new line

env -null

gives the env version

env --version

remove a variable from the environment

env -uname

prints the user name

env logname

prints all variables in the linux system

$ printenv

to list a specific variable just pass the name to the command

$ printenv SHELL

gives the path

$ printenv PATH

This command lists all environment variables available in your current shell session.

env

This filters and shows only the HOME environment variable.

env | grep HOME

TemporaryValue

env VAR_NAME="TemporaryValue" echo $VAR_NAME

Hello World

env VAR1="Hello" VAR2="World" bash -c 'echo "$VAR1 $VAR2"'

This shows the directories where the system looks for executable files.

env | grep PATH

This removes VAR_NAME for the command execution but does not unset it permanently.

env -u VAR_NAME

This starts a new bash shell with an empty environment (no variables set).

env -i bash

This runs a bash shell as the guest user with /tmp as the home directory.

env -i USER=guest HOME=/tmp bash

This returns the number of environment variables currently set.

env | wc -l

This filters out system-defined environment variables and displays only custom ones.

env | grep -vE '^(HOME|PATH|SHELL|USER|PWD|LOGNAME|TERM|LANG|DISPLAY|SSH|XDG_)'

Displays or runs a command with modified environment variables.

`env

Displays or sets environment variables.

env | grep PATH

DevOpsSchool
Typically replies within an hour

DevOpsSchool
Hi there 👋

How can I help you?
×
Chat with Us