2

I've been writing a bunch of bash scripts to make possible non-interactive, secure, cron-based SVN checkouts with CollabNet's SVN client and GNOME Keyring Daemon (aka GKD) and one of the scripts was designed to start GKD, harvest its output, essentially a couple of environment variables, and export those variables in shell of a user the script is run as. All upon user login by sourcing a bash script in ~/.bashrc.

The problem is that those environment variables will not be exported, because the script is being run in a sub-shell that exits upon it completion and environment variables get unset for good.

Well, the question is how can those variables be set permanently, meaning they're exported and kept untouched even across login-logout sessions?

1 Answer 1

1

Simply echo the variable to another shell script in your home directory (or elsewhere) starting with . (so it'll be invisible in the default ls view). Modify your .bashrc so that on startup it executes this shell script.

Example:

foo='What the heck'; echo "foo='$foo'" > ~/.startup.sh

Then put this in ~/.bashrc and you're done:

. ~/.startup.sh
6
  • Yeah, that's exactly what I've come up with only this doesn't allow to automatically launch GKD and keep its environment variables by sourcing a script in ~/.bashrc and that's what I'd love to do.
    – ILIV
    Sep 7, 2011 at 12:19
  • I mean, what I'm asking is whether there's a way to do this without creating an intermediate file on the disk.
    – ILIV
    Sep 7, 2011 at 12:24
  • Sourcing a script, sourcing a file--what's the difference? You want to maintain variables across login-logout sessions when those variables are created in such a session. The environment of a session is lost when you log out. Any persistent values have to be stored someplace outside the environment. The only possibilities I can think of are in a file or in the memory of a daemon.
    – garyjohn
    Sep 7, 2011 at 14:13
  • If you source a script that starts gnome-keyring-daemon by executing: export gnome-keyring-daemon --daemonize it won't export the variables for the user's shell, it'll export them for the sub-shell created by ~/.bashrc which is killed as soon as the script that runs the gnome-keyring-daemon exits. And it seems to me there's no way to circumvent this behavior besides creating an intermediary file. No?
    – ILIV
    Sep 7, 2011 at 14:57
  • I'm not familiar with the particulars of GKD. You could write your own daemon, though, that would store whatever data you wanted in its memory and return that data to you when queried. You could communicate with it using pipes, sockets or some other IPC mechanism. The advantage of such a daemon is that your data isn't left lying around on a disk.
    – garyjohn
    Sep 8, 2011 at 7:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .