env command tutorial in linux/unix with examples and use cases

linux env command – run a program in a modified environment

The env command executes another program after modifying the environment as specified on the command line. When the env command is used without parameters, it prints a list of current environment variables.


env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]


  • -i, –ignore-environment
    start with an empty environment
  • -0, –null
    end each output line with NUL, not newline
  • -u, –unset=NAME
    remove variable from the environment
  • -C, –chdir=DIR
    change working directory to DIR
  • -S, –split-string=S
    process and split S into separate arguments; used to pass multiple arguments on shebang lines
  • -v, –debug
    print verbose information for each processing step


Print a list of the current environment variables

➜  ~ env

Removes the specified variable from the current environment

➜  ~ env -u MAIL

Use the env command to temporarily change the environment

➜  ~ env SHELL=/bin/bash

Used to pass multiple arguments on shebang lines

Running a script named script.pl containing the following first line:

#!/usr/bin/env -S perl -w -T

Will execute perl -w -T script.pl .

Add a Comment

Your email address will not be published. Required fields are marked *