env changes the environment variables passed to a subordinate command.
This command is useful in shell scripts to form the shebang line, as it allows you to write portable scripts that do not know the location of the command you're trying to run. This comes up, for instance, when a particular program might be in the /usr/bin, /usr/local/bin, or /opt heirarchy on any given target machine. It works because while the shebang requires an absolute path to a command, you can use env as that command without a problem. Thus, to invoke moveable_command in your shell, you can write
#!/usr/bin/env moveable_command ...
and moveable_command will be found using the user's search path (PATH environment variable), and everything after that shebang line will become input to that program.
These all relate to running commands in an altered context.
- chroot - Confine the program to "jail".
- nice - Change priority.
- nohup - Protect from hangups (modem) or network outages.
- stdbuf - Change buffering of standard I/O filestreams.
- su - Change user
- timeout - Limit the time.
- gdb - Run under control of a debugger
- script - Capture all program output
- valgrind - Validate program behavior
- strace - Create a log of system calls.
- printenv - Show the environment variables.