[GTALUG] Bash does-directory-exist question

David Mason dmason at ryerson.ca
Fri Jul 10 11:11:06 EDT 2020


(base) : ~/foo ; [ -w .. ] && echo true
true
(base) : ~/foo ; /bin/pwd
pwd: .: No such file or directory
(base) : ~/foo ; pwd
/Users/dmason/foo
(base) : ~/foo ; [ -w $PWD ] && echo true
(base) : ~/foo ;

So, /bin/pwd fails and [ -w $PWD ] also fails, as John hypothesized

../Dave
On Jul 10, 2020, 11:01 AM -0400, John Sellens via talk <talk at gtalug.org>, wrote:
> On Fri, 2020/07/10 09:38:48AM -0400, Giles Orr via talk <talk at gtalug.org> wrote:
> | This gives immediate visual feedback on the write-status of the
> | current directory. But test's '-w' and '-d' both claim that you're
> | still in a valid directory under the above circumstances. Does anyone
> | know of a simple way to find out if the directory you're currently in
> | actually exists?
>
> The directory "." will still exist while you have it open (your current
> directory), but will be unreachable, as you observed with stat(1) and
> the number of links.
>
> Would checking for "test -d $PWD" work? I think $PWD is the full path
> and so if it's no longer reachable, the test should fail?
>
> Hope that helps
>
> John
> ---
> Post to this mailing list talk at gtalug.org
> Unsubscribe from this mailing list https://gtalug.org/mailman/listinfo/talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gtalug.org/pipermail/talk/attachments/20200710/42750e88/attachment.html>


More information about the talk mailing list