[GTALUG] Bash does-directory-exist question
o1bigtenor
o1bigtenor at gmail.com
Sun Jul 12 23:26:17 EDT 2020
On Sun, Jul 12, 2020 at 8:48 PM Giles Orr via talk <talk at gtalug.org> wrote:
> On Fri, 10 Jul 2020 at 17:51, John Sellens <jsellens at syonex.com> wrote:
> >
> > On Fri, 2020/07/10 05:39:59PM -0400, Giles Orr <gilesorr at gmail.com>
> wrote:
> > | I love this list! I thought that '[ -w . ]' and '[ -w $PWD ]' were
> > | practically equivalent. "Practically" means, in this case, "almost."
> > | But not quite - and the difference is the solution to the problem.
> >
> > It's a very important, though sometimes subtle, concept in unix-land
> > that there are multiple names for just about anything.
> >
> > Here, obviously, $PWD is a variable substitution equivalent to
> /some/path,
> > which likely existed at some point, but may or may not exist now. The
> > directory "." always (I think) exists, because a process always has a
> > current directory open. (Hmmm, but opendir(".") might not work?)
> >
> > The other canonical example is "how do I remove a file that starts with
> -?".
> > The key to that of course is the multiple names thing "-file" (which
> looks
> > like an option string) is the same as "./-file" (which doesn't).
> >
> > Once you understand that, the world opens up :-)
> >
> > Of course, most times "rm -- -file" works but I'm old enough (uh, I mean
> > I've read about the history of unix) to know that -- didn't always exist.
>
> Here's a simple implementation of a Bash prompt using what we were
> discussing:
>
> PS1="\$(if ! [ -w "\${PWD}" ]; then echo -en '\[\033[41m\]' ; fi ;
> echo '\w\[\033[0m\]\$ ')"
>
> Hmmmm - - - - I do believe that you suggested " . . . simple . . . ." -
- - yes?
Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gtalug.org/pipermail/talk/attachments/20200712/d3ed6e5d/attachment.html>
More information about the talk
mailing list