Shell Script Nuebie Question ->PS1/PS2 ?

Shell Script Nuebie Question ->PS1/PS2 ?

Post by Bryan Barto » Sun, 26 Feb 1995 06:06:02



I have been trying to make my first attempt at shell customization of
my environment via programming my .login and .cshrc scripts.  One
thing I've been attempting to do is to have the command prompt display
the current time, directory,a nd host.  Directory and host are no
problem, however time is.  Here's what i put in my .login file:

#${PS1:+"~`expr substr $cwd 12 100` `date '+%r'` % "}
#${PS2:+"~`expr substr $cwd 12 100` `date '+%r'` % "}
#EXPORT PS1 PS2

and my .cshrc file:

alias cd 'cd \!*;echo $cwd;set prompt="~`expr substr $cwd 12 100`
                `date '+%r'` % "'
set prompt="~`expr substr $cwd 12 100` `date '+%r'`% "

It clearly only set the time at login and directory change.  However,
assigning the shell variables PS1 and PS2 have resluted in the error:
'Variable error', which is reported on login.  Any suggestions?

 
 
 

Shell Script Nuebie Question ->PS1/PS2 ?

Post by Edmund Roche-Kel » Sun, 26 Feb 1995 07:24:46



>I have been trying to make my first attempt at shell customization of
>my environment via programming my .login and .cshrc scripts.  One
>thing I've been attempting to do is to have the command prompt display
>the current time, directory,a nd host.  Directory and host are no
>problem, however time is.  Here's what i put in my .login file:
>#${PS1:+"~`expr substr $cwd 12 100` `date '+%r'` % "}
>#${PS2:+"~`expr substr $cwd 12 100` `date '+%r'` % "}
>#EXPORT PS1 PS2
>and my .cshrc file:
>alias cd 'cd \!*;echo $cwd;set prompt="~`expr substr $cwd 12 100`
>            `date '+%r'` % "'
>set prompt="~`expr substr $cwd 12 100` `date '+%r'`% "
>It clearly only set the time at login and directory change.  However,
>assigning the shell variables PS1 and PS2 have resluted in the error:
>'Variable error', which is reported on login.  Any suggestions?

Getting the time in your prompt depends on your shell. Aliasing
cd will do nothing until you actually do change dir.

Various escape sequences exist for various shells. For example, in
tcsh, my prompt is

%B stands for bold face on

%c means basename of current directory.
%b turns bold face off.

If you look at the manual entry for your shell, it should
give you the appropriate escape sequences.
Older versions of csh and sh may not support this. tcsh is
a good shell to use, as are ksh, zsh and bash. Look at /etc/shells
on your system to find out what shells are available, and use
chsh to change your current shell. (You may not be able to do this
since it involves modifying your passwd file entry, but you can always
ask your sysadmin).

Ed

--

<a href="http://www.maths.tcd.ie/~hades/hades.html">My homepage</a>