Read a Bash variable assignment from other file
bash, scripting, shell, unix
Solution
If the file containing your variables is using bash syntax throughout (e.g. X=Y), another option is to use `source`:
#!/bin/bash
echo "Read a variable"
source test.txt
echo $EXAMPLE
Problem
I have this test script: ``` #!/bin/bash echo "Read a variable" #open file exec 6<test.txt read EXAMPLE <&6 #close file again exec 6<&- echo $EXAMPLE ``` The file `test.txt` has only one line: ``` EXAMPLE=1 ``` The output is: ``` bash-3.2$ ./Read_Variables.sh Read the variable EXAMPLE=1 ``` I need just to use the value of `$EXAMPLE`, in this case `1`. So how can I avoid getting the `EXAMPLE=` part in the output? Thanks