1

I want to set env variable in shell script. Shell script content is:

#!/bin/bash
export XDEBUG_CONFIG="idekey=PHPSTORM"

I tried both bash bin/enable_debug and bin/enable_debug. After both command I get:

$ echo $XDEBUG_CONFIG

$

However if I run export XDEBUG_CONFIG="idekey=PHPSTORM" directly in cli it works. What's wrong with my method?

FreeLightman
  • 2,224
  • 2
  • 27
  • 42
  • 3
    You need to [source](https://ss64.com/bash/source.html) your bash script for it to keep having an effect in the current shell – Aserre Dec 05 '19 at 10:54
  • Here is a cross site duplicate if you want to durably set up environment variables : https://askubuntu.com/questions/58814/how-do-i-add-environment-variables – Aserre Dec 05 '19 at 10:55
  • 4
    export makes the variables availaible in *child* processes – Rorschach Dec 05 '19 at 10:56
  • Does this answer your question? [Defining a variable with or without export](https://stackoverflow.com/questions/1158091/defining-a-variable-with-or-without-export) – Rorschach Dec 05 '19 at 10:58

1 Answers1

1

You can try running your script as below:

. bin/enable_debug

OR

source bin/enable_debug

as indicated by @Aserre

Naveen Hiremath
  • 351
  • 1
  • 8