Env: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 25: Line 25:
   
   
will display, among other environment variables, SOME_VAR.
will display, among other environment variables, SOME_VAR.
==Use <tt>env</tt> to Dynamically Modify <tt>PATH</tt>==
<syntaxhighlight lang='bash'>
python --version # returns one version
env PATH=/tmp/some-venv:${PATH} python --version # returns a different version
</syntaxhighlight>
=Use on the Shebang Line=
=Use on the Shebang Line=
{{External|https://www.baeldung.com/linux/bash-shebang-lines}}
{{External|https://www.baeldung.com/linux/bash-shebang-lines}}


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

Revision as of 23:54, 2 May 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

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.