A shell script to set an environment variable

I’m having a problem with a program that I run at work. It does a bunch of stuff1 , and then runs vim to edit the file I specified when I ran the thing. The problem is that it doesn’t run my vim, it runs the system version. And I have mine aliased to run using the -T switch to use dtterm to make my syntax highlighting work, so this program is bypassing this setting.

“Easy”, you say, “Just set your terminal type when you log in”. Nice try, mister. My function keys (F13 to F20) don’t work under dtterm (and I had a hassle getting them working at all, see earlier post so I only want to run it for vim.

To cut a long story short, I’ve written a shell script to toggle my terminal type for me, and named it term. Here it is:


#!/bin/ksh
	

T="vt220"

if [ $TERM = $T ]
then TERM=dtterm
else TERM=vt220
fi

export $TERM
echo "term set to " $TERM

There’s a gotcha with this code, a shell script can’t modify your environment variables unless you use the . to tell it to. To run my script I use the following.

. term

1 irrelevant and proprietary stuff, which I won’t start ranting about here

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

This site uses Akismet to reduce spam. Learn how your comment data is processed.