[comp.unix.wizards] PS1 and PWD in david korn's shell

tw@foobar.UUCP (Tom Walsh) (12/14/87)

In article <7@ritcv.UUCP> ccs6277@ritcv.UUCP (PUT YOUR NAME HERE) writes:
> ...in Korn Shell
...lots of work to get cwd in PS1 using korn shell
> Cliff Skolnick
> ...rochester!ritcv!ccs6277
> ...rochester!ritcv!ritcsh!sabin!lazlo!{root|ccs}
$PWD is maintained by korn shell.  use it.  it is cheaper than
`pwd`... by a  long shot.
i use
--/etc/profile--(FOR ALL USERS)
mach=`uuname -l` # could use uname -s or -n ...
--~user/.kshrc--(SALT TO TASTE)
PS1='! $mach $PWD ' ; export PS1

all done....
the "'" causes ksh to delay evaluation until printing the prompt.
there are certain versions extant that seem to have problems with
maintaining PWD accurately, and symlinks are probably neat too...

rlk@think.COM (Robert Krawitz) (12/15/87)

In article <3@dropte.foobar.UUCP> tw@dropte.UUCP (Tom Walsh) writes:
]In article <7@ritcv.UUCP> ccs6277@ritcv.UUCP (PUT YOUR NAME HERE) writes:
]$PWD is maintained by korn shell.  use it.  it is cheaper than
]`pwd`... by a  long shot.

This brings me to a major complaint about the Korn shell.

First of all, when setting my prompt in csh, I use `pwd` rather than
$cwd, because $cwd is NOT the current working directory in many cases
(symlinks most usually).  Thus, I don't really know where I am.  I
want to know where I really am.  Thus, if cd /usr actually takes me to
/usr.MC68020, I want to know that.  Of course, doing a cd .. from some
fake path is going to lose big.

Now, my complaint: ksh interprets pwd and cd .. itself.  The former I
can live with; I need merely use /bin/pwd.  The latter I cannot live
with.  I won't go into the merits of varying interpretations of
symlinks, since that issue was recently flamed to death; suffice it to
say that I prefer a link to be a link, and a symlink to be a one-way
pointer.  I also could not find a way around this in the man page.  I
now ask:  How can I turn this behavior off?

harvard >>>>>>  |
bloom-beacon >  |think!rlk	Robert Krawitz <rlk@think.com>
ihnp4 >>>>>>>>  .

ekrell@hector.UUCP (Eduardo Krell) (12/16/87)

In article <13716@think.UUCP> rlk@THINK.COM writes:

>now ask:  How can I turn this behavior off? [ksh's "cd .."]

You can't unless you have source code. ksh does (what I believe is)
the right thing w.r.t. "cd .." in a symbolic link presence.
    
    Eduardo Krell                   AT&T Bell Laboratories, Murray Hill

    {ihnp4,ucbvax}!ulysses!ekrell

lvc@tut.cis.ohio-state.edu (Lawrence V. Cipriani) (12/17/87)

In article <13716@think.UUCP>, rlk@think.COM (Robert Krawitz) writes:

>Now, my complaint: ksh interprets pwd and cd .. itself.  The former I
>can live with; I need merely use /bin/pwd.  ...
>	How can I turn this behavior off?    ...
> bloom-beacon >  |think!rlk	Robert Krawitz <rlk@think.com>

Put this alias and function in your ENV file:

alias cd=chdir

function chdir
{
	"cd" "${@}" && PWD=$(/bin/pwd)
}

When you type:

	cd [dirs]

the function chdir is executed with whatever argument(s) given to the
cd alias.  The chdir function uses the real cd (note the "cd") and
then sets PWD to the value returned by /bin/pwd.  I tried it, it works
(on Version 06/03/86) (but is noticeably slower).

Some combination of aliases and functions will usually let you do
whatever you want when one or the other isn't sufficient.

-- 
	Larry Cipriani AT&T Network Systems at
	cbosgd!osu-cis!tut!lvc Ohio State University

gwyn@brl-smoke.ARPA (Doug Gwyn ) (12/17/87)

In article <3299@ulysses.homer.nj.att.com> ekrell@hector (Eduardo Krell) writes:
>In article <13716@think.UUCP> rlk@THINK.COM writes:
>>now ask:  How can I turn this behavior off? [ksh's "cd .."]
>You can't unless you have source code. ksh does (what I believe is)
>the right thing w.r.t. "cd .." in a symbolic link presence.

Although I agree what the "right thing" is, the other behavior should
be obtainable by redefining the "cd" command (via alias or function)
to do a built-in "cd" to an absolute path obtained by chopping off the
tail of whatever /bin/pwd returns, when the "cd" command's argument is
"..".  This is obviously a kludge, and it could probably be generalized,
but it may be enough to satisfy the fellow who likes to find himselve
in strange and exciting places.

levy@ttrdc.UUCP (Daniel R. Levy) (12/18/87)

In article <3268@tut.cis.ohio-state.edu>, lvc@tut.cis.ohio-state.edu (Lawrence V. Cipriani) writes:
#> function chdir
#> {
#>       "cd" "${@}" && PWD=$(/bin/pwd)
#> }

#>The chdir function uses the real cd (note the "cd") and
#>then sets PWD to the value returned by /bin/pwd.  I tried it, it works
#>(on Version 06/03/86) (but is noticeably slower).

This won't work with older k shells (the syntax VARIABLE=$(command) that is).
Was there any particular reason to use (/bin/pwd) instead of `/bin/pwd`?
-- 
|------------Dan Levy------------|  Path: ..!{akgua,homxb,ihnp4,ltuxa,mvuxa,
|         an Engihacker @        |  	<most AT&T machines>}!ttrdc!ttrda!levy
| AT&T Computer Systems Division |  Disclaimer?  Huh?  What disclaimer???
|--------Skokie, Illinois--------|

lvc@tut.cis.ohio-state.edu (Lawrence V. Cipriani) (12/19/87)

In article <2042@ttrdc.UUCP>, levy@ttrdc.UUCP (Daniel R. Levy) writes:
	...
> This won't work with older k shells (the syntax VARIABLE=$(command) that is).
> Was there any particular reason to use (/bin/pwd) instead of `/bin/pwd`?
> Dan Levy

Just insurance since according to Dave Korn the grave accent notation,
ie `cmd`, is obsolete, and will probably be removed in a future version
of ksh.  Personally, I like the grave accent notation for quick command
line stuff and like the $(cmd) notation for scripts.

My hangup with ksh is that you cannot manipulate arguments to an alias.
I asked Dave Korn about adding this.  His response was that he had
considered it, however, his implementation would have to change drastically.
For example, command line size would be much more limited.

-- 
	Larry Cipriani AT&T Network Systems at
	cbosgd!osu-cis!tut!lvc Ohio State University