Re: is it a bug that PWD=whatever sets PS1's \w to that regardless

2021-03-17 Thread Robert Elz
Date:Wed, 17 Mar 2021 09:12:19 -0400
From:Chet Ramey 
Message-ID:  

  | If you don't modify PWD, PWD always reflects the current working directory,

Of course, but how is that relevant?

But even that isn't actually specified, if one does a popd does PWD
not change?   The description of PWD (see just below) doesn't say it does.

  | If you modify PWD, as I said, all bets are off.

Does the man page say (or even hint) at that somewhere?   The only
references I can find to PWD are in the list of variables set by
bash, which says (in its entirety)

   PWDThe current working directory as set by the cd command.

but the description of the cd command says nothing about it at all.
(It does mention OLDPWD, but only in the context of specifying what
"cd -" means).

Aside from that definition, PWD is used to define the ~+ expansion,
and as best I can tell, those are the only references to it anywhere
in the doc.

There is a list of variables:

The following variables are used by the shell.

but PWD is not in that list.  PWD is in the list:

   Shell Variables
The following variables are set by the shell:

Some of those give details about what happens when they're modified,
(eg: DIRSTACK) some are listed as read only, PWD is just as above.

How do you expect a user to know that modifying PWD might cause bash
to halt and catch fire ?

I believe some work on the doc would be useful.

kre





Re: is it a bug that PWD=whatever sets PS1's \w to that regardless

2021-03-17 Thread Chet Ramey

On 3/16/21 11:20 PM, Robert Elz wrote:


   | If you want to set PWD instead of letting cd/pushd/popd manage it,
   | all bets are off.

I agree with that as far as what you get when you expand $PWD (even the
pwd command, so using `pwd` as an alternative if PWD has been manually
set is not necessarily going to work), and even the way the cd command
works, but the bash man page says:

   \w the current working directory, with $HOME abbreviated
  with a tilde (uses the value of the PROMPT_DIRTRIM
  variable)

Nothing about $PWD there, it should be the current working directory,


If you don't modify PWD, PWD always reflects the current working directory,
as it says in its description. If you modify PWD, as I said, all bets are
off.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/



Re: is it a bug that PWD=whatever sets PS1's \w to that regardless

2021-03-16 Thread Robert Elz
Date:Tue, 16 Mar 2021 09:31:24 -0400
From:Chet Ramey 
Message-ID:  <31aff163-9e61-d34a-be79-40c7e09a8...@case.edu>

  | If you want to set PWD instead of letting cd/pushd/popd manage it,
  | all bets are off.

I agree with that as far as what you get when you expand $PWD (even the
pwd command, so using `pwd` as an alternative if PWD has been manually
set is not necessarily going to work), and even the way the cd command
works, but the bash man page says:

  \w the current working directory, with $HOME abbreviated
 with a tilde (uses the value of the PROMPT_DIRTRIM
 variable)

Nothing about $PWD there, it should be the current working directory,
according to that definition, and one thing that changing PWD does not
do is change the current working directory.

Of course, the simple fix to this is to change the man page, so refer
to $PWD instead of "the current working directory".

  | Just like setting HOME changes tilde expansion.

It does, but that's not really an analogy, ~/ is defined to be ${HOME}/
so if changing HOME did not have that effect then ~ expansion would be
broken.  If changing HOME had any effect on ~kre/ (given that the
relevant user name is used, such that it should produce what is normally
in an unaltered $HOME) however, then that would be a problem.

kre





Re: is it a bug that PWD=whatever sets PS1's \w to that regardless

2021-03-16 Thread Alex fxmbsw7 Ratchev
okay, cool, thank you for valuable infos =))

On Tue, Mar 16, 2021 at 2:31 PM Chet Ramey  wrote:

> On 3/16/21 6:23 AM, Alex fxmbsw7 Ratchev wrote:
> > .. ?
> >
> > # root ~/ogt2/confs ( 0 @ 2 ) boost ( 42098 @ 1615890149.004363 ==
> > 2021-03-16+11:22:2920 ) #
> > PWD=/bla
>
> No. If you want to set PWD instead of letting cd/pushd/popd manage it,
> all bets are off.
>
> Just like setting HOME changes tilde expansion.
>
>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>  ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/
>


Re: is it a bug that PWD=whatever sets PS1's \w to that regardless

2021-03-16 Thread Chet Ramey

On 3/16/21 6:23 AM, Alex fxmbsw7 Ratchev wrote:

.. ?

# root ~/ogt2/confs ( 0 @ 2 ) boost ( 42098 @ 1615890149.004363 ==
2021-03-16+11:22:2920 ) #
PWD=/bla


No. If you want to set PWD instead of letting cd/pushd/popd manage it,
all bets are off.

Just like setting HOME changes tilde expansion.


--
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/



Re: is it a bug that PWD=whatever sets PS1's \w to that regardless

2021-03-16 Thread Alex fxmbsw7 Ratchev
but is it a bug
its a bug to use heavy subshells for such
i understand the addment of this case tho

On Tue, Mar 16, 2021 at 1:23 PM Chris Elvidge  wrote:

> On 16/03/2021 10:23 am, Alex fxmbsw7 Ratchev wrote:
> > .. ?
> >
> > # root ~/ogt2/confs ( 0 @ 2 ) boost ( 42098 @ 1615890149.004363 ==
> > 2021-03-16+11:22:2920 ) #
> > PWD=/bla
> > # root /bla ( 0 @ 2 ) boost ( 42148 @ 1615890199.128728 ==
> > 2021-03-16+11:23:1920 ) #
> >
>
> Yes, it seems \w (and \W) take their values from $PWD
> If you want to register the current directory in $PS1 regardless, change
> \w to `pwd`
>
> --
> Chris Elvidge
> England
>
>
>


Re: is it a bug that PWD=whatever sets PS1's \w to that regardless

2021-03-16 Thread Chris Elvidge

On 16/03/2021 10:23 am, Alex fxmbsw7 Ratchev wrote:

.. ?

# root ~/ogt2/confs ( 0 @ 2 ) boost ( 42098 @ 1615890149.004363 ==
2021-03-16+11:22:2920 ) #
PWD=/bla
# root /bla ( 0 @ 2 ) boost ( 42148 @ 1615890199.128728 ==
2021-03-16+11:23:1920 ) #



Yes, it seems \w (and \W) take their values from $PWD
If you want to register the current directory in $PS1 regardless, change 
\w to `pwd`


--
Chris Elvidge
England




is it a bug that PWD=whatever sets PS1's \w to that regardless

2021-03-16 Thread Alex fxmbsw7 Ratchev
.. ?

# root ~/ogt2/confs ( 0 @ 2 ) boost ( 42098 @ 1615890149.004363 ==
2021-03-16+11:22:2920 ) #
PWD=/bla
# root /bla ( 0 @ 2 ) boost ( 42148 @ 1615890199.128728 ==
2021-03-16+11:23:1920 ) #