I use Ubuntu 16.04 with the native Bash on it.
I'm not sure if executing
#!/bin/bash
myFunc() {
export myVar="myVal"
}
myFunc
equals in any sense, to just executing export myVar="myVal"
.
Of course, a global variable should usually be declared outside of a function (a matter of convention I assume, even if technically possible) but I do wonder about the more exotic cases where one writes some very general function and wants a variable inside it to still be available to everything, anywhere.
Would export
of a variable inside a function, be identical to exporting it globally, directly in the CLI, making it available to everything in the shell (all subshells, and functions inside them)?