env- Unix, Linux Command



NAME

env - run a program in a modified environment

SYNOPSIS

env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]

DESCRIPTION

env-env is a shell command for Unix and Unix-like operating systems. It is used to either print a list of environment variables or run another utility in an altered environment without having to modify the currently existing environment. Using env, variables may be added or removed, and existing variables may be changed by assigning new values to them. In practice, env has another common use. It is often used by shell scripts to launch the correct interpreter. In this usage, the environment is typically not changed. If env is run without any options, it prints the variables of the current environment. Otherwise, env sets each NAME to VALUE and executes COMMAND.

Options

Tag Description
-i, --ignore-environment Start with an empty environment.
-0, --null End each output line with a 0 (null) byte rather than a newline.
-u, --unset=NAME remove variable NAME from the environment.
--help Display a help message and exit.
--version Display version information and exit.
- Same as -i.

EXAMPLES

Example-1:

To print out a list of all environment variables, simply run env without any arguments:

# env

output:
HOSTNAME=861d736c60b8
TERM=xterm-256color
PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/bin:/sbin:.:/usr/share/smlnj/bin
PWD=/home/cg/root
SHLVL=1
HOME=/
_=/usr/bin/env

Example-2:

To clear the environment (creating a new environment without any existing environment variables) for a new shell:

# env -i /bin/sh

output:
# env
PWD=/home/ubuntu

Example-3:

To set environment variable.

# env LOGPATH=/var/log

output:
# env
HOSTNAME=861d736c60b8
TERM=xterm-256color
PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/bin:/sbin:.:/usr/share/smlnj/bin
PWD=/home/cg/root
SHLVL=1
HOME=/
_=/usr/bin/env
LOGPATH=/var/log

Example-4:

To unset environment variable.

# env -u LOGPATH

output:
# env
HOSTNAME=861d736c60b8
TERM=xterm-256color
PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/bin:/sbin:.:/usr/share/smlnj/bin
PWD=/home/cg/root
SHLVL=1
HOME=/
_=/usr/bin/env

Example-5:

env may also be used in the hashbang line of a script to allow the interpreter to be looked up via the PATH.
test.py:
#!/usr/bin/env python2
print "Hello World."
 
output:
# python test.py
Hello World.
Print
Advertisements