Operating system | Unix, Unix-like, Inferno |
---|---|
Platform | Cross-platform |
Type | Command |
License | coreutils: GPLv3+ |
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.
The version of env
bundled in GNU coreutils was written by Richard Mlynarik, David MacKenzie, and Assaf Gordon. [1] It first appeared in 4.4BSD, and is a part of POSIX.1 (with the -i option only). [2]
GNU's env has been extended to handle signals and the current directory. [1] FreeBSD's env supports a custom search path. Extensions found in both versions include -u, for unsetting variables, and -S, for splitting arguments (mainly in shebang). [2]
To print out the set of current environment variables:
env
To create a new environment without any existing environment variables for a new shell:
env-i/bin/sh
To execute the X application xcalc and have it appear on a different display (i.e., with a modified environment whether the specified environment variable is replaced with the new value):
envDISPLAY=foo.bar:1.0xcalc
Note that this use of env is often unnecessary since most shells support setting environment variables in front of a command:
DISPLAY=foo.bar:1.0xcalc
env may also be used in the hashbang line of a script to allow the interpreter to be looked up via the PATH. For example, here is the code of a Python script:
#!/usr/bin/env python3 print("Hello, World!")
In this example, /usr/bin/env
is the full path of the env
command. The environment is not altered.
Note that it is possible to specify the interpreter without using env
, by giving the full path of the python
interpreter. A problem with that approach is that on different computer systems, the exact path may be different. By instead using env
as in the example, the interpreter is searched for and located at the time the script is run (more precisely, env
does a system call to execvp
, which does the job of locating the interpreter and launching it). This makes the script more portable, but also increases the risk that the wrong interpreter is selected because it searches for a match in every directory on the executable search path. It also suffers from the same problem in that the path to the env
binary may also be different on a per-machine basis.
AWK is a domain-specific language designed for text processing and typically used as a data extraction and reporting tool. Like sed and grep, it is a filter, and is a standard feature of most Unix-like operating systems.
Bash, short for Bourne-Again SHell, is a shell program and command language supported by the Free Software Foundation and first developed for the GNU Project by Brian Fox. Designed as a 100% free software alternative for the Bourne shell, it was initially released in 1989. Its moniker is a play on words, referencing both its predecessor, the Bourne shell, and the concept of rebirth.
A shell script is a computer program designed to be run by a Unix shell, a command-line interpreter. The various dialects of shell scripts are considered to be command languages. Typical operations performed by shell scripts include file manipulation, program execution, and printing text. A script which sets up the environment, runs the program, and does any necessary cleanup or logging, is called a wrapper.
A Unix shell is a command-line interpreter or shell that provides a command line user interface for Unix-like operating systems. The shell is both an interactive command language and a scripting language, and is used by the operating system to control the execution of the system using shell scripts.
In computing, ls
is a command to list computer files and directories in Unix and Unix-like operating systems. It is specified by POSIX and the Single UNIX Specification.
The cd
command, also known as chdir
, is a command-line shell command used to change the current working directory in various operating systems. It can be used in shell scripts and batch files.
In software development, Make is a command-line interface software tool that performs actions ordered by configured dependencies as defined in a configuration file called a makefile. It is commonly used for build automation to build executable code from source code. But, not limited to building, Make can perform any operation available via the operating system shell.
In Unix-like and some other operating systems, the pwd
command writes the full pathname of the current working directory to the standard output.
basename is a standard computer program on Unix and Unix-like operating systems. When basename is given a pathname, it will delete any prefix up to the last slash ('/'
) character and return the result. basename is described in the Single UNIX Specification and is primarily used in shell scripts.
uname is a computer program in Unix and Unix-like computer operating systems that prints the name, version and other details about the current machine and the operating system running on it.
wc
is a command in Unix, Plan 9, Inferno, and Unix-like operating systems. The program reads either standard input or a list of computer files and generates one or more of the following statistics: newline count, word count, and byte count. If a list of files is provided, both individual file and total statistics follow.
In computing, cp
is a command in various Unix and Unix-like operating systems for copying files and directories. The command has three principal modes of operation, expressed by the types of arguments presented to the program for copying a file to another file, one or more files to a directory, or for copying entire directories to another directory.
cksum
is a command in Unix and Unix-like operating systems that generates a checksum value for a file or stream of data. The cksum command reads each file given in its arguments, or standard input if no arguments are provided, and outputs the file's 32-bit cyclic redundancy check (CRC) checksum and byte count. The CRC output by cksum is different from the CRC-32 used in zip, PNG and zlib.
rm
is a basic command on Unix and Unix-like operating systems used to remove objects such as computer files, directories and symbolic links from file systems and also special files such as device nodes, pipes and sockets, similar to the del
command in MS-DOS, OS/2, and Microsoft Windows. The command is also available in the EFI shell.
In computing, sleep is a command in Unix, Unix-like and other operating systems that suspends program execution for a specified time.
In computing, a shebang is the character sequence #!, consisting of the characters number sign and exclamation mark, at the beginning of a script. It is also called sharp-exclamation, sha-bang, hashbang, pound-bang, or hash-pling.
In Unix-like operating systems, true
and false
are commands whose only function is to always return with a predetermined exit status. Programmers and scripts often use the exit status of a command to assess success or failure (non-zero) of the command. The true
and false
commands represent the logical values of command success, because true returns 0, and false returns 1.
In computing, which
is a command for various operating systems used to identify the location of executables. The command is available in Unix and Unix-like systems, the AROS shell, for FreeDOS and for Microsoft Windows. The functionality of the which command is similar to some implementations of the type command. POSIX specifies a command named command that also covers this functionality.
dirname
is a standard computer program on Unix and Unix-like operating systems. When dirname
is given a pathname, it will delete any suffix beginning with the last slash ('/'
) character and return the result. dirname
is described in the Single UNIX Specification and is primarily used in shell scripts.
In Unix and Unix-like operating systems, printf is a shell builtin that formats and outputs text like the same-named C function.