shell prompts
there are 4 variables that define the command line prompt:
- PS1
- PS2
- PS3
- PS4
Added information in our PS2 prompt
This prompt appears if you have not completed the command properly,
it may appear to be "hung". A control C or break or delete command
should release you.
EXAMPLE: PS2="*--> additional input required: > "; export PS2
Wait, HOW do I set the prompt variable?
Depending on the version of your operating system you will have to do one
of the following to allow the prompt to work, this is done at the command
line or in the .profile or .kshrc files:
1) declare and export
2) export
or
3) declare
examples:
1) PS1="`hostname`.`whoami`--> " ; export PS1
2) export PS1="`hostname`.`whoami`--> "
3) PS1="`hostname`.`whoami`--> "
Added information in our PS1 prompt
Often times we wish to see certain information before we execute a command.
For example:
1) where we're at in a directory.
2) who we're logged in as
3) which system we're on
4) even the date and time (although it won't be updated continously)
We can view the entire path or just the current working directory. Below
are prompts (PS1) that will provide that visibility. ( the C shell
is not recommended, so emphasis is placed on Korn/Bourne and Posix shells)
Present Working Directory - Korn / Posix Shell only
a prompt that wraps the line:
This prompt displays:
--------------------------------------
username@hostname [present directory]
>-->
the code is:
PS1=" -----------------------------------------------------
$(/usr/bin/whoami)@$(/usr/bin/hostname) [\$PWD]
>--> "; export PS1
#############################################################################
This prompt is useful for a DTTERM, as it places userid, hostname and pwd in the title bar:
export WHMI=$(/usr/bin/whoami)
export WHST=$(/usr/bin/hostname)
export PS1="$(print '\001\015\001\0033]2; $WHMI ---> \"$WHST\" ---> $PWD \007
-----------------------------------------------------
$WHMI@$WHST [$PWD]
>-->\001 ')"
How do I get the current directory into my prompt?
This prompt is to display ONLY the directory name, without the path information.
-----------------------------------------------------------------------
#######################################################################
#
# How do I get the current directory into my prompt?
#
#######################################################################
#
# Korn Shell (ksh):
#
# Put this in your .profile file to display the full path:
# PS1='$PWD $ '
#
# If you just want ONLY the last component of the directory, use:
# PS1='${PWD##*/} $ '
#
#######################################################################
#
# Bourne Shell (sh):
#
# If you have a newer version of the Bourne Shell (SVR2 or newer)
# you can use a shell function to make your own command, "xcd" say:
#
# xcd() { cd $* ; PS1="`pwd` $ "; }
#
# If you have an older Bourne shell, it's complicated but not
# impossible. Here's one way. Add this to your .profile file:
#
# LOGIN_SHELL=$$ export LOGIN_SHELL
# CMDFILE=/tmp/cd.$$ export CMDFILE
# # 16 is SIGURG, pick a signal that's not likely to be used
# PROMPTSIG=16 export PROMPTSIG
# trap '. $CMDFILE' $PROMPTSIG
#
# and then put this executable script (without the indentation!),
# let's call it "xcd", somewhere in your PATH
#
# : xcd directory - change directory and set prompt
# : by signalling the login shell to read a command file
# cat #${CMDFILE?"not set"} <
|