Env: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 13: Line 13:


  /usr/bin/env bash
  /usr/bin/env bash
=Options=
==<tt>-u</tt>==
If the environment variable whose name follows <code>-u</code> is in the environment, remove it before processing the remaining options. The value for name must not include the ‘=’ character.


=No Argument Use=
=No Argument Use=

Revision as of 22:55, 30 October 2023

External

Internal

Overview

Run a command with a modified environment, or just print the environment if no argument is provided.

/usr/bin/env [utility]
/usr/bin/env bash

Options

-u

If the environment variable whose name follows -u is in the environment, remove it before processing the remaining options. The value for name must not include the ‘=’ character.

No Argument Use

Displays environment values.

Modify the Environment to Run a Command

env SOME_VAR='some value' printenv

will display, among other environment variables, SOME_VAR.

Use env to Dynamically Modify PATH

python --version # returns one version
env PATH=/tmp/some-venv:${PATH} python --version # returns a different version

Use on the Shebang Line

https://www.baeldung.com/linux/bash-shebang-lines

The env command works by instructing the system to look for the specified interpreter through the PATH variable and use the first occurrence found.