how you can read in thread title, I'm deploying a bash script in which I have to export some variables inside it.
But (I think you know) the export command works only inside the script and so, on exit command, the variables aren't set like I set inside the script.
Consequently in env file, variables are set like before the run of the script.
So, the question is easy: how can I set permanently the variables inside the script with export command?
No.
if you have a script that sets and/or exports variables that are needed by another script,
you need to source the script that sets the environment inside the script that needs the new environment.
For example:
env_script.sh
export var1=value1 var2=value2 ...
main_script.sh
# source the env script
. /path/to/env_script.sh
# here the values of var1 and var2 are available
If you need to do something different, please be more specific.
Another approach if you just want to make the results of a called script available to the parent. Echo the results at the end of the called script and read the results in the parent script:
idro, if I'm understanding the source of your confusion:
Environment variables are not global variables. You can't permanently set them for every other program, from one program. The closest thing there is to setting them globally is /etc/profile, and processes don't automatically get changes when you alter that -- it's read by shells on login and so forth.
How env vars work is child processes get copies from their parent on creation and thereafter are independent -- changes in the parent don't affect the child and vice versa.