An environment variable is a value available in your computer globally, which may contain anything from the path to the root directory, the home directory, and a secret token.
This command can reveal the list of these environment variables. It can also be used to add, update and remove a variable.
General syntax for env command:
$ env [OPTION]… [-] [NAME=VALUE]… [COMMAND [ARG]…]
1. Run a process without the existing environment variables
env -i your_command
The -i or –ignore-environment option runs the command with an empty environment
Example: Type env -i /bin/sh to create a new environment without any existing environment variables.
2. Add an environment variable
env variable_name
Use the env variable_name command to set a new environment variable.
Example: Set a new environment variable named Example.
3. Remove an environment variable
env -u variable_name
Use the -u or –unset option to remove the variable from the environment.
Example: Removing the Example environment variable. As you can see in the screenshot, the variable we recently created no longer exists.
4. Remove the line break from the environment variables list
env -0
The -0 or –null option ends each line of output with a 0 (null) byte, not a newline.
Example: Using the env command to separate output lines with the NULL character.
More Linux commands:
Directory Operations
rmdir · cd · pwd · exa · ls
File Operations
cat · cp · dd · less · touch · ln · rename · more · head
File System Operations
chown · mkfs · locate
Networking
ping · curl · wget · iptables · mtr
Search and Text Processing
find · grep · sed · whatis · ripgrep · fd · tldr
System Information and Management
env · history · top · who · htop · glances · lsof
The post How to Use the Env Command in Linux appeared first on Hongkiat.
No responses yet