How to change or customise login prompt for ksh shell in Linux (with examples)

In my last article I had shown the steps to customise login prompt for bash shell

How to customize and change color of the bash login prompt in Linux
10 examples to customize or change the login prompt using PS1 variable of bash shell in Linux

so now in this article I will share some examples which can be used to customise login prompt for 'ksh shell'

By default in Red Hat Linux we only get a "$" prompt for ksh shell

First let us create a user with default shell as 'ksh'

# useradd  -s /bin/ksh deepak

As you see we only get a dollar ($) prompt for ksh shell based user

# su - deepak
Last login: Thu Feb 15 09:27:42 IST 2018 on pts/0

Display only hostname

export PS1='[${HOSTNAME}]$ '


Display username and hostname

export PS1='[${USER}@${HOSTNAME}]$ '


Display hostname with current working directory

export PS1='[${HOSTNAME}:${PWD}]$ '


Display user, hostname and current working directory

export PS1='[${USER}@${HOSTNAME}:${PWD}]$ '


To make the changes permanent, place your PS1 variable to .kshrc in the user home folder

# .kshrc

# Source global definitions
if [ -f /etc/kshrc ]; then
        . /etc/kshrc

# use emacs editing mode by default
set -o emacs

# User specific aliases and functions

export PS1='${USER}@${HOSTNAME}:${PWD}> '

I hope the article was useful.