Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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

On my AIX box, which is using ksh as the default shell, I'd like the prompt to show both the date and time followed by a newline \n, along with the name of the machine, and the working directory.

Something like:

2014/08/05 10:58:43
[username]machinename:/some/path/here $

I've tried the following:

unset _Y _M _D _h _m _s
eval $(date "+_Y=%Y;_M=%m;_D=%d;_h=%H;_m=%M;_s=%S")
typeset -Z2 _h _m _s
_tsub="(_m=(SECONDS/60%60)) == (_h=(SECONDS/3600%24)) + (_s=(SECONDS%60))"
_timedhms=$_Y'/'$_M'/'$_D" "'${_x[_tsub]}$_h:$_m:${_s}'

PS1="$_timedhms'\n' "'[USERNAME]MACHINE:${PWD#$HOME/} $ '

However, there is no newline between the date/time and the rest of the prompt. It seems now matter what the combination of quotes I try, I cannot get a newline to appear in PS1.

Edit: nixed the spaces after SECONDS assignment, and edits need to be 6 characters long, so I'm telling you here.

share|improve this question
Double quoted strings in ksh do not automatically interpret \n as a newline. As Gnouc demonstrates there are workarounds. – chicks Aug 5 '14 at 17:30
up vote 3 down vote accepted

You can use the literal newline in PS1:


or using $'\n' with ksh93:

PS1="$_timedhms$'\n' [USERNAME]MACHINE:${PWD#$HOME/} $ "
share|improve this answer
The literal newline works, however the $'\n' does not appear to work at all. I just get an n displayed inline. – Max Vernon Aug 5 '14 at 17:37
It seems only work with ksh93. Updated my answer. – cuonglm Aug 5 '14 at 17:48

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.