BASH Prompt Customization
Updated: 11/03/2004
General Information
In this short tutorial I shall explain the basics of BASH prompt customization. I won't cover the more advanced aspects, and probably won't cover colours, but just enough to make your prompt display the information that you want to know.Requirements
Meeting .profile
I installed FreeBSD 4.9 on my new server a few days ago, and installed BASH for users (I use csh for root - but that's another topic). When I created a user, their prompt would look like this:|
-bash-2.05b$ |
| # | pico -w .profile |
|
# $FreeBSD: src/share/skel/dot.profile,v 1.19.2.2 2002/07/13 16:29:10 mp Exp $ # # .profile - Bourne Shell startup script for login shells # # see also sh(1), environ(7). # # remove /usr/games and /usr/X11R6/bin if you want PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin:$HOME/bin; export PATH # Setting TERM is normally done through /etc/ttys. Do only override # if you're sure that you'll never log in via telnet or xterm or a # serial line. # Use cons25l1 for iso-* fonts # TERM=cons25; export TERM BLOCKSIZE=K; export BLOCKSIZE EDITOR=pico; export EDITOR PAGER=more; export PAGER # set ENV to a file invoked each time sh is started for interactive use. ENV=$HOME/.shrc; export ENV |
Customization
Okay then, let's start customizing our prompt. BASH reads from the PS1 variable to determine what to display as your prompt; if there isn't a PS1 variable, it displays -bash-2.05b$.|
PS1="\u@\h:\w$ "; export PS1 configure@bsd:/home/configure$ |
|
a Makes the computer "beep". \d Displays the date in "Weekday Month Date" format. \h Displays short hostname. \H Displays complete hostname including domain. \w Displays current working directory. \n Makes the prompt move to a new line. \s Displays the name of the shell, e.g. BASH \t Displays the current time in 24 hour HH:MM:SS format. \T Displays the current time in 12 hour HH:MM:SS format. \@ Displays the current time in 12 hour am/pm format. \u Displays your username. \! Displays the number of commands in the history file (.bash_history). \# Displays the number of commands you have executed in your current session. |
|
PS1="[\t - \d]\n\u@\H:\w[\s]$" [11:04:12 - Monday September 17] configure@bsd.mydomain.com:/home/configure[BASH]$ |
This guide is © 2004 - 2012 configure.
Author: configure
configure at dteq dot org