I have bash script: myscript.sh. Here is the content:
#!/bin/bash
function my_func {
echo "my_func start"
echo $MY_VARIABLE # THIS PRINTS NOTHING
echo "my_func end"
}
function func2 {
}
echo "after my_func"
echo $MY_VARIABLE # this prints "YES"
I want to call only function my_func from command line with environment variable "MY_VARIABLE". I launch script with this command:
MY_VARIABLE=YES source myscript.sh; my_func
Here is the output:
after my_func
YES
my_func start
my_func end
Variable $MY_VARIABLE inside my_func() is empty. I want that variable $MY_VARIABLE in my_func() were equal to "YES".