Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my .bashrc file I configured how I would like my prompt to be displayed. My .bashrc is sourced in .bash_profile. The command in the .bashrc file is:

PS1='[\t] \u@\h is $PWD :: '

I switched the user (for me) timezone to GMT+0 using tzselect. The problem I am having is that using the date command I am getting the GMT time (which I am pleased with) but the terminal prompt is still on the system time (even after logging in and logging out), which I am not pleased with.

How can I get the terminal to display the time in the time format that I, the user, am specifying?

share|improve this question
up vote 5 down vote accepted

You don't say how you set the timezone, but since you set it for your own user, that has to be by setting the TZ variable. Bash (at least version 4.1.5) has some quirks when it comes to taking a TZ change into account: the change is only reflected after the shell has started an external command (it has to be an external command, forking a subshell isn't enough, nor is executing built-ins).

bash-4.1$ PS1='\t '
12:31:05 export TZ=Asia/Tokyo
12:31:13 echo foo
12:31:14 /bin/echo foo

So if you set TZ in your .bash_profile and you don't happen to start an external command, you will still see the time in the old timezone at the first prompt.

export TZ=GMT
# Refresh bash's idea of $TZ for prompt display purposes.
# As of bash 4.1, this requires running an external command!
if [[ $- = *i* ]]; then command true; fi
share|improve this answer
bash-4.2 reacts immediately to a change in TZ. Apparently that's been the case since 2.0 (tiswww.case.edu/php/chet/bash/CHANGES). – Mat May 31 '12 at 6:55
@Mat My tests showed otherwise. Upon further investigation (in bash 4.1), bash only takes a TZ change into account after it has executed an external command (!). So it works, but not immediately. – Gilles May 31 '12 at 10:36
Ok, needs bash >= 4.2.6 - patch 4.2.5 makes it work, 4.2.6 fixes a segfault in that patch :-) – Mat May 31 '12 at 10:45
thanks for the solution. Interesting enough. The machine this is occurring on is running bash3.00.15(1)-release. I am not able to get it to work with this version even with the suggestions. Though I am able to get it to work at home where I am running 4.2.8(1). Again, thank you. – DanCat May 31 '12 at 15:49
@DanCat Did you try execing another copy, as I suggested in my original answer? I edited that out because it's complex and my assertion that it was the only way turned out to be wrong in bash 4.1. Maybe you need to do that in older versions; if so I'll edit it back in. – Gilles May 31 '12 at 19:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.