Generic UNIX Interactive PromptsThe following Korn/POSIX, BASH, C, and TurboC Shell prompts are for displaying the user's hostname and present working directory. Be careful to use the exact characters, quotes, and syntax. See the last section for instructions on how to invoke shell environment changes without having to log out and back in again. The venerable Bourne shell, from which the Korn and POSIX shells are descended, does not provide for interactive prompts. C (CSH) and TurboC (TCSH) Shells
setenv HOST `uname -n` alias setprompt 'set prompt="$HOST($cwd)%"' alias cd 'cd \!* && setprompt' alias pushd 'pushd \!* && setprompt' alias popd 'popd \!* && setprompt' setpromptThe resulting prompt would look like this:
Korn (KSH) and POSIX (SH) Shells
ENV=~/.kshrc export ENV The POSIX shell requires that the following lines be placed into the .profile file located in the user's home directory to invoke a secondary ENVIRONMENT file: ENV=~/.shrc export ENVPrompt Type 1: Place the following into the .kshrc or .shrc file: HOST=$(uname -n) export HOST PS1='$HOST:$PWD $' export PS1The resulting prompt would look like this:
HOST=$(uname -n) export HOST PS1='$HOST:$PWD $ ' export PS1The resulting prompt would look like this:
$ Bourne-Again Shell (BASH)
PS1='\h:$PWD $' export PS1The resulting prompt would look like this:
PS1='\h:$PWD \n$' export PS1The resulting prompt would look like this:
$ Further BASH Prompt CustomizationThe BASH allows prompt string customization by using these backslash-escaped characters: \a an ASCII bell character (07) \d the date in "Weekday Month Date" format (e.g., "Tue May 26") \e an ASCII escape character (033) \h the hostname up to the first `.' \H the hostname \n newline \r carriage return \s the name of the shell, the basename of $0 (the portion following the final slash) \t the current time in 24_hour HH:MM:SS format \T the current time in 12_hour HH:MM:SS format \@ the current time in 12_hour am/pm format \u the username of the current user \v the version of bash (e.g., 2.00) \V the release of bash, version + patchlevel (e.g., 2.00.0) \w the current working directory \W the basename of the current working directory \! the history number of this command \# the command number of this command \$ if the effective UID is 0, a #, otherwise a $ \nnn the character corresponding to the octal number "nnn" \\ a backslash \[ begin a sequence of non_printing characters \] end a sequence of non_printing charactersTherefore, ASCII escape characters could be used to create a colourful BASH prompt and include an embedded carriage return: PS1="\[\033[1;32m\]\h\033[0;30m\]:\[\033[1;36m\]\u\033[0;30m\]:\033[1;31m\]\$PWD\[\033[0;30m\]\n$ " export PS1The resulting BASH prompt would look like this:
$ Here are the rest of the colour equivalences: Black 0;30 Dark Gray 1;30 Blue 0;34 Light Blue 1;34 Green 0;32 Light Green 1;32 Cyan 0;36 Light Cyan 1;36 Red 0;31 Light Red 1;31 Purple 0;35 Light Purple 1;35 Brown 0;33 Yellow 1;33 Light Gray 0;37 White 1;37 Restarting the Shell Environment After ChangesWith all shells, remember to source (restart) your environment files after making any changes in them (i.e. .profile, .kshrc, .shrc, .bashrc, .cshrc, .tcshrc, .login). BOURNE, KSH, POSIXThe first step is to source the .profile:. .profileThis reads: dot The second step (except for the Bourne shell, which does not allow an ENVIRONMENT file) is to source the file assigned to the ENV variable: . .shrc (POSIX) . .kshrc (KSH) BASHThe only step is to source the .bashrc:. .bashrc CSH and TCSHThese shells use the command source rather than a dot:source .cshrc (CSH) source .tcshrc (TCSH) Click Here to jump to my Custom Solaris System Administration Labs page. |