Hi,
It is mentioned that, to set the PS1 variable to show the present working directory PS1="\$pwd >" is enough. Can any one explain what is the back slash in that command does.
The difference is that pwd is uppercased in my example.
The backslash is interesting, they always are actually.
If you try the command without the backslash it seems to work and your prompt is set to your current directory. But if you *change* directory the prompt doesnt change; for that you need the backslash.
In the shell a backslash means "the next character is *not* special". So when $PS1 is evaluated by the shell (each time a prompt is displayed) it evaluates the string '$PWD' which is a variable maintained by the shell to always contain your currrent directory. (without the backslash the evaluation is done only once, when you set $PS1)
When you set your PS1 to PWD is ok.
But your prompt can become like this:
/opt/graphics/common/newconfig/opt/graphics/common/10.0_Rel_Notes>
It leaves you little space to type.
With this method:
CD(){
cd $1
PS1=$(basename $(dirname $PWD))/$(basename $PWD)
if [ -d /$PS1 ] ;then
PS1=$PWD
else
PS1=.../$PS1
fi
PS1="[$(hostname):$PS1]# "
}
alias cd='CD'
Your prompt will look like:
[Host02:.../common/config]#
When you have only one machine you can skip the hostname.
I use the HP10.20 /usr/bin/sh posix .
I placed the alias and function in the .kshrc so it will only
run at startup of the shell.
Mike thanks. I did not know that. Gregor.Weertman@mailcity.com
The "not enough space left" problem is a pain I know. I set mine like this:
[tt]
export PS1="$(hostname):\$PWD
>"
[/tt]
This leaves you with a complete line to type on but *does* take up two lines for a prompt - which some ppl don't like. I always wondered how the path truncation thing was done by the way - thanks. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.