Bash Tips: Set Remote Variables

As I’ve mentioned, I’m now on DreamHost. It’s pretty dreamy (as you might expect), but screen is not allowed. This is a slight inconvenience, since I rather like screen and use it constantly. Plan B involves running screen locally and SSH’ing to DreamHost in every window, but I lose my tailored bash prompt. Normally, my prompt looks like this:

adam@aziz[0]:~$

I can immediately tell that screen is running, as well as my window number. This breaks down as soon as I SSH to DreamHost. I get a far more generic prompt:

aestus@jezebel:~$

So, what to do? Set a variable on the remote side, in a roundabout sort of way:

ssh -t jezebel.dreamhost.com 'export MYVAR=myvalue &&
      exec /bin/bash --login'

It doesn’t look like much. It took me an hour to assemble. SSH to the host, allocating a TTY with -t. Run bash on the remote side as a login shell, executing the specified command. Export a variable, and exec a sub-bash.

Yeah, that’s it.

Update 12/15/2005: Trimmed the command a bit: the outer /bin/bash call is unnecessary.

One Comments

  1. Histrionic says:

    It scares me when it takes you “an hour to assemble” anything. Eek.

Leave a Comment

HTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>