I'm currently writing a script which uses a variable i created via terminal by typing the commend:
export NUM_brightness=10
Now the script is attempting to increase the variable by 1, By doing:
NUM_brightness=$((NUM_brightness+1))
And just in case i also added
export NUM_brightness=$NUM_brightness
However when i run the script again the variable NUM_brightness does not increased and even stays the same as the first time i typed in the terminal: export NUM_brightness=10
Meaning it keeps NUM_brightness with value of 11 instead increasing it.
My question is how do i make the bash script to update the variable NUM_brightness so every time i run the script NUM_brightness will keep on increasing?
Here is the script:
NUM_brightness=$((NUM_brightness+1))
echo $NUM_brightness
NUM_temp="0.$NUM_brightness"
echo $NUM_temp
if [ "NUM_brightness" >=11 ]; then
NUM_brightness=1
NUM_temp=1
fi
export NUM_brightness=$NUM_brightness;
echo $NUM_brightness
When you use a sub-shell, like using a script, you can't change the parent environnement.
script_name) you source the script (. script_nameorsource script_name).bashrc,.profile) and then call the function, which just happens to look like a script invocation (eg,script_namevsfunction_name)