4

Is the a way to specify a multi line prompt in Korn shell?

I am planning to swhitch from bash to ksh. In bash I have a very simplistic prompt, but it is 2 line prompt. I hate when input position changes depending on directory depth. My PS1 in bash is:

PS1='$(echo $?): \w\n>> '

Which results in prompt like:

0: /var/log
>> _
7

Just put an embedded newline inside the string:

PS1='$(echo $?): $PWD
>> '
  • Such a trivial thing! I tried putting newline char and it did not work. Did not think about explicitly putting newline. – Andreas Nov 7 '11 at 12:38
  • 1
    May I suggest you change the >> to something else? '> or >> in a prompt may lead to nasty results if you accidentally cut&paste your screen contents. Maybe » or with an UTF-8 charset is also a nice prompt and has no special meaning for a shell. – ktf Nov 7 '11 at 15:51
  • $'\n' will embed a newline too. – amphetamachine Nov 8 '11 at 0:06
  • @amphetamachine, not in my Ksh. Where you tried that? – manatwork Nov 8 '11 at 8:37
  • I think $'string' is bash only which wouldn't help here. The embedded newline approach is probably the easiest way to do it. – jw013 Nov 8 '11 at 20:25
0

This seems to work for me on ksh

PS1=$'$HOSTNAME $PWD\n$ '

The output is like below

myhost /user/varghese
$ 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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