[TriLUG] BASH Question: Putting relative local time and user environment v ariables in the prompt

Jon Carnes jonc at nc.rr.com
Fri Sep 27 20:22:45 EDT 2002


On Fri, 2002-09-27 at 16:26, Jaimie Livingston wrote:
> Here's the situation...
> I have an OpenBSD system that is used by several staffers in the US and
> Europe. 
> The server is set to use GMT as the localtime, but I would like to have a
> bash prompt that displays the users time for their timezone.

Boy talk about a waste of time...

If this is the server that I'm thinking of, then it really doesn't need
to be set to GMT, you can save yourself some grief and set the server to
the proper timezone.
>  
> I assume, possibly incorrectly, that I will have to set the TZ environ
> variable for the user via a login script, and then use /t (or /T, or /@) to
> display the time in the prompt, and echo the setting for the TZ environ
> variable to indicate their timezone.
>  
> I have two problems:
> 1) I can't figure out which dot file I should set the TZ prompt from.
>    I've tried the following (assuming US Eastern as the timezone):
>         in .bashrc and .bash_profile
>                         TZ=:/US/Eastern 
>         and
>             TZ=/usr/share/zoneinfo/US/Eastern
>  
>                 in .login and .profile
>                         TZ=:/US/Eastern
>                         export TZ
>                 and
>             TZ=/usr/share/zoneinfo/US/Eastern
>             export TZ
>  
>     But to no avail. The time is still returned using GMT as set with
> /etc/localtime.
>     Perhaps I am misreading the various Bash HOWTO's...

Modifying the TZ variable doesn't seem to do anything to the time
displayed by my bash prompt... I'm using bash version 2.05.1

>  
> 2) I don't know how to echo the TZ environment variable in a prompt, can't
> find a reference for doing it, and don't even know if it's possible... Any
> information you can provide would be helpful...

You can look at all the environment variables by simply typing "set". If
you want to isolate the TZ variable then, "set |grep TZ".

===
I can think of one way to do this - but it's not worth the effort... 
I read an article about two years ago that detailed how to run a
program/script with every prompt, and display the output as part of the
prompt.

I think the author wanted to display the size of the directory on the
prompt. Then he could simply "cd" to a directory to see how much space
was used there.  

I remember thinking that it was a stupid bash trick!

Jon




More information about the TriLUG mailing list