You are not logged in.

#1 2010-08-25 02:12:46

marfig
Member
From: Portugal
Registered: 2010-07-30
Posts: 189
Website

[SOLVED] (bash) Not being able to export variable

I suspect the following script is not exporting the DEADKS environment variable I need for it to function properly. I'm running it from a urxvt terminal:

#!/bin/bash
# ~/bin/deadkeys_switch
# Switch dead keys on/off

if [ -z "${DEADKS+x}" ]; then
    export DEADKS="1"
fi

if [ "$DEADKS" = "1" ]; then
    DEADKS="0"
    xmodmap -e "keycode 35 = acute grave dead_acute dead_grave dead_tilde dead_macron"
    xmodmap -e "keycode 51 = asciitilde asciicircum dead_tilde dead_circumflex dead_grave dead_breve"

else
    DEADKS="1"
    xmodmap -e "keycode 35 = dead_acute dead_grave dead_acute dead_grave dead_tilde dead_macron"
    xmodmap -e "keycode 51 = dead_tilde dead_circumflex dead_tilde dead_circumflex dead_grave dead_breve"
fi

export DEADKS

Once I run it the first time, I manage to disable deadkeys as I intended (most certainly because of the first check). But running it again does not re-enable them as I would like to. On the command prompt running the following command produces a null output:

echo $DEADKS

What am I doing wrong?

Last edited by marfig (2010-08-25 03:02:41)


I probably made this post longer than it should only because I lack the time to make it shorter.
- Paraphrased from Blaise Pascal

Offline

#2 2010-08-25 02:41:36

marfig
Member
From: Portugal
Registered: 2010-07-30
Posts: 189
Website

Re: [SOLVED] (bash) Not being able to export variable

I have changed my script to this:

#!/bin/bash
# ~/bin/deadkeys_switch
# Switch dead keys on/off

if [ -n "${DEADKS-x}" ]; then
    export DEADKS="1"
fi

if [ "$DEADKS" = "1" ]; then
    dks="0"
    xmodmap -e "keycode 35 = acute grave dead_acute dead_grave dead_tilde dead_macron"
    xmodmap -e "keycode 51 = asciitilde asciicircum dead_tilde dead_circumflex dead_grave dead_breve"

else
    dks="1"
    xmodmap -e "keycode 35 = dead_acute dead_grave dead_acute dead_grave dead_tilde dead_macron"
    xmodmap -e "keycode 51 = dead_tilde dead_circumflex dead_tilde dead_circumflex dead_grave dead_breve"
fi

export DEADKS=$dks

And this is the output from debug mode, no matter how many times I run it:

+ '[' -n x ']'
+ export DEADKS=1
+ DEADKS=1
+ '[' 1 = 1 ']'
+ dks=0
+ xmodmap -e 'keycode 35 = acute grave dead_acute dead_grave dead_tilde dead_macron'
+ xmodmap -e 'keycode 51 = asciitilde asciicircum dead_tilde dead_circumflex dead_grave dead_breve'
+ export DEADKS=0
+ DEADKS=0

I probably made this post longer than it should only because I lack the time to make it shorter.
- Paraphrased from Blaise Pascal

Offline

#3 2010-08-25 02:52:53

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] (bash) Not being able to export variable

Source that file.

#!/bin/bash
# ~/test/keys

DEADKS="0"
export DEADKS
[karol@black test]$ echo $DEADKS

[karol@black test]$ . keys
[karol@black test]$ echo $DEADKS
0

Last edited by karol (2010-08-25 02:57:33)

Offline

#4 2010-08-25 03:02:23

marfig
Member
From: Portugal
Registered: 2010-07-30
Posts: 189
Website

Re: [SOLVED] (bash) Not being able to export variable

Oh, thank you Karol. That solves it

Kind of a bummer, though. Having to do it every time i need to run it. But not a big problem.

Thank you once again.


I probably made this post longer than it should only because I lack the time to make it shorter.
- Paraphrased from Blaise Pascal

Offline

#5 2010-08-25 03:10:15

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] (bash) Not being able to export variable

Can you put it in your .bashrc

foo () { ~/test/keys && . ~/test/keys; }

?

Offline

#6 2010-08-25 03:13:32

marfig
Member
From: Portugal
Registered: 2010-07-30
Posts: 189
Website

Re: [SOLVED] (bash) Not being able to export variable

Well, I intend to run it only on demand. I'm planning something similar and wrap it around a launcher script.

EDIT: I understand your suggestion now, karol. I didn't know I could do that. Thanks. It's ideal.

Last edited by marfig (2010-08-25 03:40:14)


I probably made this post longer than it should only because I lack the time to make it shorter.
- Paraphrased from Blaise Pascal

Offline

Board footer

Powered by FluxBB