Env(command)

From LQWiki
Jump to: navigation, search

env changes the environment variables passed to a subordinate command.

Under some shells (bash for instance) there are builtins to do at least the display functionality.

Special Trick

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.

Provided by

Most (all?) Linux distributions that have this at all incorporate it from the GNU Coreutils: and use its man page

Related Commands

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.

See also

  • printenv - Show the environment variables.

This article is a stub and needs to be finished. Plunge forward and help it grow!