-1

I have to set 10 env variables (setenv). I saved all these env variable in a filename.env. Is there a way to set all the variable inside the file with single command ?

I tried with "source filename.env", variables are getting set but many other things are also happening. Doubt what I did is wrong. Please help.

Edit: content of filename.env:

setenv variable1 value1
setenv variable2 value2
.
.
setenv variable10 value10
4
  • 4
    What’s in the file and what, exactly, are the “many other things?” Commented Jan 15, 2018 at 13:22
  • 4
    Why not add the content of your .env file to your question? Commented Jan 15, 2018 at 13:26
  • 3
    What shell are you using? csh? Commented Jan 15, 2018 at 13:32
  • using cshc @ilkkachu Commented Jan 16, 2018 at 12:07

1 Answer 1

3

in bash:

With the following file ~/variables.rc:

export test1="test1"
export test2="test2"
export test3="test3"
export test4="test4"
export test5="test5"

You can source the file. Those sourced variables are then known in your terminal session:

[ws] user ~ >source variables.rc  
[ws] user ~ >echo $test3
test3

in csh:

With the following file ~/variables.rc:

setenv test1 test10
setenv test2 test20
setenv test3 test30
setenv test4 test40
setenv test5 test50

You can source the file. Those sourced variables are then known in your terminal session:

[ws] user ~ >source variables.rc  
[ws] user ~ >echo $test3
test30
5
  • if "setenv" instead of "export" same working ? Commented Jan 16, 2018 at 10:00
  • It depends on your shell: unix.stackexchange.com/questions/368944/… Commented Jan 16, 2018 at 10:15
  • What shell are you using? Commented Jan 16, 2018 at 10:15
  • 1
    I am using cshc @kevin Commented Jan 16, 2018 at 12:07
  • Saved my days, in a project I got about 15 variables :D Commented Apr 28, 2020 at 10:36

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.