Skip to main content
Fixed a typo requested by the OP in the comments
Source Link

Recently I noticed we have 3 options to set environment variables:

  1. export envVar1=1
  2. setenv envVar2=2envVar2 2
  3. env envVAr3=3envVar3=3

If there are any other ways, please enlighten us.

When should I prefer one over the other? Please suggest guidelines.

As for shell compatibility, which is the most expansive (covers more shell dialects)?

I already noticed this answer but I wish to expand the question with env and usage preference guidelines.

Recently I noticed we have 3 options to set environment variables:

  1. export envVar1=1
  2. setenv envVar2=2
  3. env envVAr3=3

If there are other ways, please enlighten us.

When should I prefer one over the other? Please suggest guidelines.

As for shell compatibility, which is the most expansive (covers more shell dialects)?

I already noticed this answer but I wish to expand the question with env and usage preference guidelines.

Recently I noticed we have 3 options to set environment variables:

  1. export envVar1=1
  2. setenv envVar2 2
  3. env envVar3=3

If there are any other ways, please enlighten us.

When should I prefer one over the other? Please suggest guidelines.

As for shell compatibility, which is the most expansive (covers more shell dialects)?

I already noticed this answer but I wish to expand the question with env and usage preference guidelines.

edited tags
Link
Gilles 'SO- stop being evil'
  • 866.1k
  • 205
  • 1.8k
  • 2.3k
Source Link
Maroshi
  • 569
  • 1
  • 4
  • 5

What is the difference between env, setenv, export and when to use?

Recently I noticed we have 3 options to set environment variables:

  1. export envVar1=1
  2. setenv envVar2=2
  3. env envVAr3=3

If there are other ways, please enlighten us.

When should I prefer one over the other? Please suggest guidelines.

As for shell compatibility, which is the most expansive (covers more shell dialects)?

I already noticed this answer but I wish to expand the question with env and usage preference guidelines.