0

so I have create setup.sh file like this :

#!/bin/bash
export SP_TWITTER_KEY=adsfad
export SP_TWITTER_SECRET=aadsfadsf
export SP_TWITTER_ACCESSTOKEN=asdfasdfa
export SP_TWITTER_ACCESSSECRET=asdfasdfas

export mongo_connection=localhost

and after that I run this command in order to turn the file to be executable :

$ chmod +x setup.sh

finally execute the file so that all my env varible are exported. I have tried several ways like this :

$ . /setup.sh
$ .setup.sh
$ bash setup.sh

But none of them are working, because I check again the variable like mongo_connection and others are still empty. Any idea what's wrong or am I missing something?

NOTE : I'm using tmux to run my shell terminal

3

Without any change into your script you can simply run in like this:

. setup.sh

or

source setup.sh

it will cause your variables to be set in the current shell otherwise bash will open a non-interactive shell, runs your command into that and after it's finish, it closes that shell.

for more explanation, help source:

source: source FILENAME
Execute commands from a file in the current shell.
Read and execute commands from FILENAME in the current shell.

  • it looks like my problem is when I execute my setup.sh in another shell on tmux. It doesnt export on the other shell – Gujarat Santana May 21 '17 at 9:09
  • 1
    When you export a variable it will only be available in child process of that shell not others, if you want to set something globally you can put it in places like .bashrc . – Ravexina May 21 '17 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.