[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: pwd and prompt don't update after deleting current working directory
From: |
Phi Debian |
Subject: |
Re: pwd and prompt don't update after deleting current working directory |
Date: |
Fri, 12 Jul 2024 05:47:03 +0200 |
Oops I forgot the reply to all in my reply to @David Hedlund
<davidh@gnu.org>
I was on the same tune as you @greg@wooledge.org <greg@wooledge.org>.
==================================
On Fri, Jul 12, 2024 at 12:14 AM David Hedlund <davidh@gnu.org> wrote:
>
>
> When a directory is deleted while the user is inside it, the terminal
> should automatically return to the parent directory.
>
>
Jeez, this looks like pretty dangerous isn't it, imagine a script (or a
fast typer for interactive shell) the is doing some bookeeping inside a
directory, (i.e removing some files in the $PWD), and $PWD is unlinked by
another random process, then your script (or fast typer, who type and read
afterwards) would then continue its bookeeping in the parent (of login
shell dir?). It make no sense.
So when a $PWD is unlinked while working in it, the only things a shell can
do is to emit a message like
$ rm -rf $PWD
$ >xyz
bash: xyz: No such file or directory
Now you may argue this is not explicit enough, nothing in there tells you
that the $PWD was unexpectedly unlinked. You may implement something more
explicit like this for interactive shell, for script simply bail out on
error.
$ PS1='$(ls $PWD>/dev/null 2>&1||echo $PWD was unlinked)\n$ '
$ pwd
/home/phi/tmp/yo
$ ls
asd qwe rty
$ rm -rf $PWD
/home/phi/tmp/yo was unlinked
$ ls
/home/phi/tmp/yo was unlinked
$ cd ..
$ mkdir -p yo/asd ; >yo/qwe >yo/rty ; cd yo
$ pwd
/home/phi/tmp/yo
=====================================
Bottom line, this is not a bug, and there is no enhancement request here.
Or 'may be'
on bash error
bash: xyz: No such file or directory
the full path could be expanded
bash: /home/phi/tmp/yo/xyz: No such file or directory
But even that I am not sure.
- Re: pwd and prompt don't update after deleting current working directory, (continued)
- Re: pwd and prompt don't update after deleting current working directory, Lawrence Velázquez, 2024/07/11
- Re: pwd and prompt don't update after deleting current working directory, Chet Ramey, 2024/07/12
- Re: pwd and prompt don't update after deleting current working directory, David Hedlund, 2024/07/16
- Re: pwd and prompt don't update after deleting current working directory, Chet Ramey, 2024/07/16
- Re: pwd and prompt don't update after deleting current working directory, Lawrence Velázquez, 2024/07/16
- Re: pwd and prompt don't update after deleting current working directory, David Hedlund, 2024/07/16
- Re: pwd and prompt don't update after deleting current working directory, Martin D Kealey, 2024/07/19
- Re: pwd and prompt don't update after deleting current working directory, David Hedlund, 2024/07/19
Re: pwd and prompt don't update after deleting current working directory, Robert Elz, 2024/07/11
Re: pwd and prompt don't update after deleting current working directory, David, 2024/07/11