Operating System - HP-UX
1820647 Members
2344 Online
109626 Solutions
New Discussion юеВ

Re: how to set PS1 in csh

 
SOLVED
Go to solution
eagle_2
Advisor

how to set PS1 in csh

I can set PS1 in korn shell like the following:
export PS1='mesap:$LOGNAME $PWD>'

but how i can set PS1 in c shell like this style?
thanks
5 REPLIES 5
V.Tamilvanan
Honored Contributor
Solution

Re: how to set PS1 in csh

Hi,


set prompt="mesap:$LOGNAME $PWD\>"


See the man pages for csh.
H.Merijn Brand (procura
Honored Contributor

Re: how to set PS1 in csh

This will not do what you expect because of two reasons:

1. you single quote the prompt
2. csh does not know of $PWD and $LOGNAME

so if you set the prompt using

set prompt='mesap: $LOGNAME $PWD> '

it will prompt like

mesa: $LOGNAME $PWD>

not what you want. The default csh only knows about the exclamation mark, which is - unless escaped with a \ - replaced with the current command history buffer event number.

When you switch to more enhanced csh's, like tcsh - the best csh clone IMHO - you have a complete ouvre of interpreted specials. My prompt is like

set prompt="$prod%{`tput smul`%}%M:%{`tput rmul;tput dim`%}%/ %h %#%{`tput sgr0`%} "

for intelligent terminals (xterm) and

set prompt="$prod%B%M:%/ %h %# %b"

for simple vt320 emulators

tcsh is available from ftp://ftp.astron.com/pub/tcsh/ (source), http://hpux.connect.org.uk/hppd/hpux/Shells/tcsh-6.12.03/ (HP porting center) or - the most recent shiny new 6.13.00 - from my HP site:

USA Los Angeles http://mirrors.develooper.com/hpux/
SGP Singapore https://www.beepz.com/personal/merijn/
USA Chicago http://ww.hpux.ws/merijn/
NL Hoofddorp http://www.cmve.net/~merijn/

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
H.Merijn Brand (procura
Honored Contributor

Re: how to set PS1 in csh

Just for fun. Here's the list of tcsh prompt escapes:

prompt The string which is printed before reading each
command from the terminal. prompt may include any
of the following formatting sequences (+), which
are replaced by the given information:

%/ The current working directory.
%~ The current working directory, but with one's
home directory represented by `~' and other
users' home directories represented by `~user'
as per Filename substitution. `~user' substi?
tution happens only if the shell has already
used `~user' in a pathname in the current ses?
sion.
%c[[0]n], %.[[0]n]
The trailing component of the current working
directory, or n trailing components if a digit
n is given. If n begins with `0', the number
of skipped components precede the trailing
component(s) in the format `/trail?
ing'. If the ellipsis shell variable is set,
skipped components are represented by an
ellipsis so the whole becomes `...trailing'.
`~' substitution is done as in `%~' above, but
the `~' component is ignored when counting
trailing components.
%C Like %c, but without `~' substitution.
%h, %!, !
The current history event number.
%M The full hostname.
%m The hostname up to the first `.'.
%S (%s)
Start (stop) standout mode.
%B (%b)
Start (stop) boldfacing mode.
%U (%u)
Start (stop) underline mode.
%t, %@
The time of day in 12-hour AM/PM format.
%T Like `%t', but in 24-hour format (but see the
ampm shell variable).
%p The `precise' time of day in 12-hour AM/PM
format, with seconds.
%P Like `%p', but in 24-hour format (but see the
ampm shell variable).
\c c is parsed as in bindkey.
^c c is parsed as in bindkey.
%% A single `%'.
%n The user name.
%j The number of jobs.
%d The weekday in `Day' format.
%D The day in `dd' format.
%w The month in `Mon' format.
%W The month in `mm' format.
%y The year in `yy' format.
%Y The year in `yyyy' format.
%l The shell's tty.
%L Clears from the end of the prompt to end of
the display or the end of the line.
%$ Expands the shell or environment variable name
immediately after the `$'.
%# `>' (or the first character of the promptchars
shell variable) for normal users, `#' (or the
second character of promptchars) for the supe?
ruser.
%{string%}
Includes string as a literal escape sequence.
It should be used only to change terminal
attributes and should not move the cursor
location. This cannot be the last sequence in
prompt.
%? The return code of the command executed just
before the prompt.
%R In prompt2, the status of the parser. In
prompt3, the corrected string. In history,
the history string.

`%B', `%S', `%U' and `%{string%}' are available in
only eight-bit-clean shells; see the version shell
variable.


And here's the list for bash:

prompt PS1 when it is ready to read a command, and the
secondary prompt PS2 when it needs more input to complete
a command. Bash allows these prompt strings to be cus?
tomized by inserting a number of backslash-escaped special
characters that are decoded as follows:
\a an ASCII bell character (07)
\d the date in "Weekday Month Date" format
(e.g., "Tue May 26")
\D{format}
the format is passed to strftime(3) and the
result is inserted into the prompt string;
an empty format results in a locale-specific
time representation. The braces are
required
\e an ASCII escape character (033)
\h the hostname up to the first `.'
\H the hostname
\j the number of jobs currently managed by the
shell
\l the basename of the shell's terminal device
name
\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
\A the current time in 24-hour HH:MM format
\u the username of the current user
\v the version of bash (e.g., 2.00)
\V the release of bash, version + patchelvel
(e.g., 2.00.0)
\w the current working directory
\W the basename of the current working direc
tory
\! 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,
which could be used to embed a terminal con?
trol sequence into the prompt
\] end a sequence of non-printing characters

Escapes for the posix sh:

PS1 The value of this parameter is expanded for parameter
substitution, to define the primary prompt string. The
default value is "$ ". The character ! in the primary
prompt string is replaced by the command number. See
the "Command Reentry" subsection.

For the ksh:

PS1 The value of this parameter is expanded for
parameter substitution, to define the primary
prompt string which, by default, is $ followed by
a space character. The character ! in the
primary prompt string is replaced by the command
number (see Command Re?entry below). To include a
! in the prompt, use !!.

ksh, bash, and posix-sh interpret environment variables in the prompt on *every* evaluation, which enables you to use

PS1='$PWD > '

you do have to use single quotes

Need I say more? :)

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
eagle_2
Advisor

Re: how to set PS1 in csh

Thank you for your information.
It's really good
Balaji_18
New Member

Re: how to set PS1 in csh

I believe you would have got the answer for your question by now. If not, then the answer for your question is

set prompt = "mesap:`echo $LOGNAME` `pwd` \>"