help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why does a shell script need current directory?


From: Andreas Kusalananda Kähäri
Subject: Re: Why does a shell script need current directory?
Date: Sun, 14 Feb 2021 08:42:20 +0100

On Sat, Feb 13, 2021 at 08:17:31PM -0600, Peng Yu wrote:
> > The part of the paragraph that you omitted makes it pretty clear
> > that a value of PWD inherited in the environment must correspond
> > to the current working directory (which necessarily has to exist)
> > to be considered.  Even then, there are many cases in which the
> > shell has license to ignore it.
> 
> I have to say the POSIX manual is confusing. According to the
> following text, if PWD is specified from the environment, does shell
> have to check the absolute pathname of the current working directory?
> 
> """
> If a value for PWD is passed to the shell in the environment when it
> is executed, the value is an absolute pathname of   the current
> working directory that is no longer than {PATH_MAX} bytes including
> the terminating null byte, and the value does not contain any
> components that are dot or dot-dot, then the shell shall set PWD to
> the value from the environment.
> """
> 
> If so, this doesn't make too much sense. If the shell needs to check
> the absolute path of the current working directory anyway, why does it
> bother whether PWD is specified in the environment. It seems that this
> double requirement is either unnecessary, or I misunderstood
> something.

Note that the current directory may have multiple absolute paths (via
symbolic links, for example).  So this gives the user a way of choosing
which absolute pathname should be used for PWD.

-- 
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden

.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]