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: Lawrence Velázquez
Subject: Re: Why does a shell script need current directory?
Date: Sat, 13 Feb 2021 12:27:29 -0500

> On Feb 13, 2021, at 9:46 AM, Peng Yu <pengyu.ut@gmail.com> wrote:
> 
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
> 
> POSIX says this. I am not sure if I understand it correctly. But it
> seems that PWD should be initialized from the environment? If so, why
> even the following won't work?
> 
> $ PWD=/tmp /tmp/main.sh
> shell-init: error retrieving current directory: getcwd: cannot access
> parent directories: No such file or directory
> 
> """
> PWD
>    Set by the shell and by the cd utility. In the shell the value
> shall be initialized from the environment as follows....
> """

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.

vq



reply via email to

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