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'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
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
$
$
Last login: Thu Feb 15 09:27:42 IST 2018 on pts/0
$
$
Display only hostname
export PS1='[${HOSTNAME}]$ '
[Ban17-adm01-a-br]$
[Ban17-adm01-a-br]$
Display username and hostname
export PS1='[${USER}@${HOSTNAME}]$ '
[deepak@Ban17-adm01-a-br]$
[deepak@Ban17-adm01-a-br]$
Display hostname with current working directory
export PS1='[${HOSTNAME}:${PWD}]$ '
[Ban17-adm01-a-br:/home/deepak]$
[Ban17-adm01-a-br:/home/deepak]$
Display user, hostname and current working directory
export PS1='[${USER}@${HOSTNAME}:${PWD}]$ '
[deepak@Ban17-adm01-a-br:/home/deepak]$
[deepak@Ban17-adm01-a-br:/home/deepak]$
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
fi
# use emacs editing mode by default
set -o emacs
# User specific aliases and functions
export PS1='${USER}\@${HOSTNAME}:${PWD}\> '
# Source global definitions
if [ -f /etc/kshrc ]; then
. /etc/kshrc
fi
# 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.