TAYENGSI%NUSDISCS.BITNET@cunyvm.cuny.edu,Marvin Tay@BRL.MIL (03/24/89)
To all prompt enthusiasts, I hope this is not too late an entry. In an earlier article, Brian Fristensky <fristens@ncsugn.ncsu.edu> sez' >> In MS-DOS there is a very easy way to get the current directory displayed as >> part of the prompt (prompt $p). In UNIX, there is certainly no >> straightforward way to do this. Can anyone think of a tricky way? Well, for all Korny (bad pun!) users, we have a rather simple solution which is to include the following line in your .profile : PS1='"$PWD" >' Neat huh ? Aliases gave me some problems at first so an alternative is to use a shell function like this : ncd () { cd $1; PS1='"$PWD" >' ;} Anymore suggestions ? Note: ncd is derived from chronic over-dependence on my PC's Norton Utilities. +------------------------ Marvin Tay tayengsi@nusdiscs.bitnet Disclaimer : I am just an innocent harmless student expressing innocent harmless views. HENCE, any views expressed are entirely my own and in no way reflect those held by the esteemed institution that I belong to. " .....uucp is unheard of in this region.....and Singapore is *NOT* in China..............." +------------------------
tneff@well.UUCP (Tom Neff) (03/25/89)
Actually not even the classic Korn shell solution of export PS1='$PWD> ' seems to work everywhere. On about half the machines I visit, if you try this you get a literal prompt of $PWD> -- i.e., the string isn't interpreted before display. I have never been too scientific about why this is, since it's not all that important to me, but I think most of the trouble has been on BSD implementations of ksh. Perhaps there's something in the BSD port that broke this. -- Tom Neff tneff@well.UUCP or tneff@dasys1.UUCP
bph@buengc.BU.EDU (Blair P. Houghton) (03/27/89)
In article <11080@well.UUCP> tneff@well.UUCP (Tom Neff) writes: >Actually not even the classic Korn shell solution of > > export PS1='$PWD> ' > >seems to work everywhere. On about half the machines I visit, if you >try this you get a literal prompt of $PWD> -- i.e., the string isn't >interpreted before display. I have never been too scientific about why >this is, since it's not all that important to me, but I think most of >the trouble has been on BSD implementations of ksh. Perhaps there's >something in the BSD port that broke this. I don't know ksh, but all the other shells I've seen use single-quotes to protect against variable substitution... --Blair '$WITTICISM' "Oops."
hjespers@vpk4.UUCP (Hans Jespersen) (03/27/89)
In article <2391@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes: >In article <11080@well.UUCP> tneff@well.UUCP (Tom Neff) writes: >>Actually not even the classic Korn shell solution of >> >> export PS1='$PWD> ' >> >>seems to work everywhere. >I don't know ksh, but all the other shells I've seen use single-quotes >to protect against variable substitution... Absolutely correct. I think Tom ment export PS1=`$PWD> ` ^ ^ --------------------------------------------------------------------------- Hans Jespersen UUCP: uunet!attcan!hjespers AT&T Canada Inc. or ..!attcan!nebulus!arakis!hans Toronto, Ontario #include <std.disclaimer> "Yabba Dabba Doo" -- F. Flintstone
dik@cwi.nl (Dik T. Winter) (03/27/89)
In article <4549@vpk4.UUCP> hjespers@attcan.UUCP (Hans Jespersen) writes: > In article <2391@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes: > >In article <11080@well.UUCP> tneff@well.UUCP (Tom Neff) writes: > >>Actually not even the classic Korn shell solution of > >> > >> export PS1='$PWD> ' > >I don't know ksh, but all the other shells I've seen use single-quotes > >to protect against variable substitution... Same for ksh. > Absolutely correct. I think Tom ment > export PS1=`$PWD> ` > ^ ^ No. The contents of PS1 must be $PWD> and it will be evaluated when doing the prompt. This is of course very ksh specific. -- dik t. winter, cwi, amsterdam, nederland INTERNET : dik@cwi.nl BITNET/EARN: dik@mcvax
rob@PacBell.COM (Rob Bernardo) (03/27/89)
In article <4549@vpk4.UUCP> hjespers@attcan.UUCP (Hans Jespersen) writes: +In article <2391@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes: +>In article <11080@well.UUCP> tneff@well.UUCP (Tom Neff) writes: +>>Actually not even the classic Korn shell solution of +>> +>> export PS1='$PWD> ' +>> +>>seems to work everywhere. + +>I don't know ksh, but all the other shells I've seen use single-quotes +>to protect against variable substitution... + +Absolutely correct. I think Tom ment + + export PS1=`$PWD> ` + ^ ^ Absolutely wrong. :-) The above will set PS1 to be your current working directory ***at the time it was set***. It will not change from command to command no matter how much you "cd". On the other hand, the following: export PS1='$PWD> ' will set PS1 to literally be "$PWD> ". Then, you ask, wouldn't the prompt come out as literally "$PWD> ". The answer is no. The two environmental variables ENV and PS1 undergo variable substitution by ksh *when used*. This is why you can put $PWD in PS1 and have it reflect your cwd as it changes with each command. -- Rob Bernardo, Pacific Bell UNIX/C Reusable Code Library Email: ...![backbone]!pacbell!pbhyf!rob OR rob@pbhyf.PacBell.COM Office: (415) 823-2417 Room 4E850O San Ramon Valley Administrative Center Residence: (415) 827-4301 R Bar JB, Concord, California
bbadger@x102c.harris-atd.com (Badger BA 64810) (03/28/89)
In article <4549@vpk4.UUCP> hjespers@attcan.UUCP (Hans Jespersen) writes: >In article <2391@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes: >>In article <11080@well.UUCP> tneff@well.UUCP (Tom Neff) writes: >>>Actually not even the classic Korn shell solution of >>> >>> export PS1='$PWD> ' >>> >>>seems to work everywhere. > >>I don't know ksh, but all the other shells I've seen use single-quotes >>to protect against variable substitution... > >Absolutely correct. I think Tom ment > > export PS1=`$PWD> ` > ^ ^ [.signature deleted] The original is correct: >>> export PS1='$PWD> ' Note single quotes:^ ^ The ``correction'' is incorrect: > export PS1=`$PWD> ` Note back-quotes: ^ ^ The reason for using single quotes is to prevent the shell from evaluating $PWD at the time of defining exported variable PS1. What *should* happen then is that the string value of PS1 is subject to parameter substitution *at the time the prompt is printed*. In that case the *current* value of PWD can be substituted. I gather from your experience that not all implementations of ksh work the same way. Perhaps another variable must be set to trigger evaluation of the prompt? This is sometimes done to retain compatibility with older shell scripts. If the ``special variable'' is not set, then the older compatible features are used. (I'm not saying it *is* so, just that this is a possibility. Versions of csh I've used have this feature for 'lineeditmode' and 'filec', for instance.) The documentation I have for ksh variable PS1 states: PS1 The value of this parameter is expanded for parameter substitution to define the primary promt string which by default is ``$''. The character ! in the primary prompt string is replaced by the *command* number (See Command Re-entry below). There doesn't seem to be any doubt here that export PS1='$PWD> ' should execute correctly, giving the present working directory set by the cd command. Maybe you have an impoverished version of ksh? Maybe you're really running sh? I seem to have the same problem with the 'tcsh' I'm running, none of the recently posted strings such as: set prompt="%m: (%h)" have worked for me. I just get the literal string. My tcsh does do command line editing, file name completion and inline history completion, but the prompt string doesn't seem to do any prompt-time substitutions. By the way, in .cshrc I use this: if (! $?prompt) exit #not an interactive subshell? set prompt_="`uname -n`>" set prompt="`tput smso`${prompt_}`tput rmso` " if ($?WINDOW_ME || $?DISPLAY ) then set ti_ts="`tput ts`" #to status line set ti_fs="`tput fs`" #return from status line alias titl 'echo -n ${ti_ts}${prompt_}": `dirs`"${ti_fs}' #delayed vars endif Of course this could be done more simply as: set prompt="`tput smso;uname -n;echo '>';tput rmso` " alias titl 'echo -n "`tput ts;uname -n; echo -n :;dirs;tput fs`"' but I think the variable substitution method above is faster to execute. This solves some of the problems with terminal-dependent code, by using SYS V's tput command. ``tput'' is a simple program, but I haven't seen it ported to BSD/termcap. Anyone out there know if this has been done? Bernard A. Badger Jr. 407/984-6385 |``Use the Source, Luke!'' Secure Computer Products |``Get a LIFE!'' -- J.H. Conway Harris GISD, Melbourne, FL 32902 |Buddy, can you paradigm? Internet: bbadger%x102c@trantor.harris-atd.com|'s/./&&/' Tom sed expansively.
tneff@well.UUCP (Tom Neff) (03/28/89)
In article <4549@vpk4.UUCP> hjespers@attcan.UUCP (Hans Jespersen) writes: >In article <2391@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes: >>In article <11080@well.UUCP> tneff@well.UUCP (Tom Neff) writes: >>>Actually not even the classic Korn shell solution of >>> >>> export PS1='$PWD> ' >>> >>>seems to work everywhere. > >>I don't know ksh, but all the other shells I've seen use single-quotes >>to protect against variable substitution... > >Absolutely correct. I think Tom ment > > export PS1=`$PWD> ` > ^ ^ >--------------------------------------------------------------------------- >Hans Jespersen UUCP: uunet!attcan!hjespers >AT&T Canada Inc. or ..!attcan!nebulus!arakis!hans >Toronto, Ontario #include <std.disclaimer> Is this a forgery or did an AT&T employee really just suggest using backquotes in the above example? The effect would be to attempt to *execute* the current directory while redirecting stdout nowhere. Actually the effect would be to set the prompt string to "syntax error" or some variant thereof. :-) I repeat, PS1='$PWD> ' -- with single quotes -- works under KornShell Version 06/03/86d 386 Release 1.2, which is what I run. On other systems I have used, you may have to use double quotes instead; under whatever version of ksh they are running on my distributor's 3b2, not even that works. Sometimes the symptom is unwanted early substitution as alluded to by Jesperson; sometimes you can't get it to interpret in any form, you just get a $PWD> in your face. Since ksh source is available from the toolchest, I assume some versions I encounter have been built on-site; perhaps there's a touchy spot in the area of the code that works differently depending on your compiler. Who knows. -- Tom Neff tneff@well.UUCP or tneff@dasys1.UUCP
hjespers@vpk4.UUCP (Hans Jespersen) (03/28/89)
In article <4896@pbhyf.PacBell.COM> rob@PacBell.COM (Rob Bernardo) writes: >In article <4549@vpk4.UUCP> hjespers@attcan.UUCP (Hans Jespersen) writes: >>Absolutely correct. I think Tom ment >> export PS1=`$PWD> ` >Absolutely wrong. :-) The above will set PS1 to be your current working >directory ***at the time it was set***. It will not change from command >to command no matter how much you "cd". On the other hand, the following: > export PS1='$PWD> ' Opps. I guess I just made an _Absolute_ fool of myself. The correct version is of course (export PS1='$PWD> ') or (export PS1="$PWD> "). You see my .kshrc has (export PS1=`uname`'$PWD> ') and unlike pwd uname generally never changes ;-) My apologies for confusing the issue, it's just that I've seen this topic go by so many times that I don't give it any thought anymore. BTW. Is anyone working on a monthly/bi-weekly posting of "answers to most frequently asked questions". If not, I will gladly volunteer (and I promise to get it right this time ;-) -- Hans Jespersen UUCP: uunet!attcan!hjespers AT&T Canada Inc. or ..!attcan!nebulus!arakis!hans Toronto, Ontario #include <std.disclaimer> "Yabba Dabba Doo" -- F. Flintstone
bruce@idsssd.UUCP (Bruce T. Harvey) (03/29/89)
In article <4549@vpk4.UUCP>, hjespers@vpk4.UUCP (Hans Jespersen) writes: > In article <2391@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes: > >In article <11080@well.UUCP> tneff@well.UUCP (Tom Neff) writes: > >> export PS1='$PWD> ' > Absolutely correct. I think Tom ment > export PS1=`$PWD> ` Nope. Tom meant '$PWD' when he said it. The reason for the single quotes is so that the shell where the definition is being made does not interpret $PWD. If it did, the current working directory of _that_shell_ would _always_ display. By quoting it, four characters ($, P, W, and D) are exported and not interpreted by ksh _until_displayed_. I don't think sh- does any interpretation of displayed variables in this manner, which is why it doesn't work this way using sh-. If you use back-quotes, as in above, you end up trying to execute a directory. (" ... Hmm. I wonder if that's why directories must be x-ecutable to be used ...") -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Bruce T. Harvey (B-}> | ... cp1!sarin!wb3ffv!idsssd!idssup!bruce (Title depends on day) | ... ctnews!idsssd!idssup!bruce (301) 584-1960 | Convergent Route Distribution Sys. - Hunt Valley, MD