- I have a simple shell script that flips an environment variable from value
bar, or the other way round, depending on its current value.
- I use F12 to trigger this script, and I know that works.
- When the script is triggered, the new value doesn't persist when the script ends.
What am I doing wrong?
1. The script:
My script checks whether the environment variable is present, or creates it if missing:
if [ -z $COLEMAK ];then export COLEMAK="qwerty";fi
Then the script flips the value from whatever it was to the other value:
if [ "$COLEMAK" == "qwerty" ]
then export COLEMAK="colemak" ; xmodmap ~/colemak.map
else export COLEMAK="qwerty" ; xmodmap ~/qwerty.map
Note that besides flipping the variable value, the script uses
xmodmap to remap the keyboard from one layout to another. This is the core purpose of the script, and that's why I want to trigger it from a function key.
I know that this script only works when it is sourced (
. ~/foo.sh), and that works well from the virtual terminal. So far so good.
.xbindkeysrc.scm to include
(xbindkey '(F12) "term &") and that correctly executes the command when I press F12. So far so good.
I modified that line to read
(xbindkey '(F12) ". ~/foo.sh &"). I know the script runs because it writes a log line when I press F12, but the change in the environment variable does not persist after the script ends.