env: command not found

The env command is used to run a command with modified environment variables. By supplying the name of a variable and a value in the key–value pair format, as well as supplying a command to run, you can change the value of the specified variable for that particular command session. If the variable does not exist, it will be added to the environment. Likewise, you can use the -u option to remove the specified variable from the environment in which the specified command runs. Consider using env if you want to override values in child processes or add new ones.

Issuing the command without any arguments will display all variables in the environment as well as their corresponding values.

Syntax

The syntax of the env command is:

# env [options] [NAME=value] [command]

If you encounter the below error while running the dd command:

dd: command not found

you may try installing the below package as per your choice of distribution:

Distribution Command
OS X brew install coreutils
Debian apt-get install coreutils
Ubuntu apt-get install coreutils
Alpine apk add coreutils
Arch Linux pacman -S coreutils
Kali Linux apt-get install coreutils
CentOS yum install coreutils
Fedora dnf install coreutils
Raspbian apt-get install coreutils

env Command Examples

1. Show the environment:

# env

2. Run a program. Often used in scripts after the shebang (#!) for looking up the path to the program:

# env program

3. Clear the environment and run a program:

# env -i program

4. Remove variable from the environment and run a program:

# env -u variable program

5. Set a variable and run a program:

# env variable=value program

6. Set multiple variables and run a program:

# env variable1=value variable2=value variable3=value program
Related Post