Lonely Shell Variables – Part 2
Back in March 2008 I wrote a blog here called Lonely Shell Variables. Today I was fiddling with shell variables in D3 (also called Environment variables) and once again I marvelled at the power and flexibility – but I’d bet the number of people who really use this functionality can be counted on a single hand. Today, in an unusually long post, I’ll go back over some basics, and provide some insight that you won’t find anywhere else.
Indeed these @Variables are extremely lonely, almost never discussed in public, probably never visited by anyone but the most geeky among us. I can imagine a couple of these little gems huddled in the dm,var, file (discussed below), cold because no one ever opens that file to let in any warmth, wondering amongst themselves why they don’t get the same attention as more popular features like triggers or even F-correlatives.
Once again, what are these shell variables (which I refer to here as @vars)? They are like BASIC Common variables, so they hold a value from one program to the next, but they also work at TCL too. So while MyVar in Common can only be used in BASIC, you can set and use @MyVar in BASIC, at TCL, in Procs, in Dict items, in Paragraphs, in Macros, and perhaps other interesting places.
“I use environment variables all the time”, you say? Ah, you’re probably talking about the defaults: @USER, @ACCOUNT, and maybe @PIB. Sure, you can use these in BASIC like this:
CRT "Your user ID is " : @USER : "
CRT "and today is " : @DATE
And everyone knows @AM, @VM, and @SVM (nick-named @SM) … but do you every really think of these as “shell variables”? I’m guessing you figured these are just special extensions in BASIC, but these and all @vars can be used just about everywhere in the system.
Those are the popular ones. Do you know their “siblings”? : @MESSAGES, @PATH, or @PROMPT? How about @DAY, @MONTH, and @YEAR? Try this at TCL:
That should make your TCL prompts look like this:
Notice the “set name” verb? To unset an @var, just uh, use “unset name”. (That will get your normal TCL prompt back, just like a logoff.)
Where can you find all of this variable goodness? See the D3 reference manual, section “Terminal Control Language > TCL Overview > @ Shell Variable”. Also look for the penv command. While it can be a bit cryptic, the manual explains how to use environment variables. So for example, you can do this:
list customers with last-order-date = “@yesterday” last-order-date
And you can use your new @Yesterday shell variable anywhere in D3. That’s fine if you want to manually enter the date every day, but what about calculating @Yesterday so that it’s always accurate? We’ll see how to do that soon.