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: Peng Yu
Subject: Re: Why does a shell script need current directory?
Date: Sat, 13 Feb 2021 08:46:31 -0600

Given built-n command pwd is available, why not delay the execution of
getting the current working directory until it is needed?

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....
"""

On 2/12/21, Seth David Schoen <schoen@loyalty.org> wrote:
> Peng Yu writes:
>
>> Hi,
>>
>> I run the following script in a directory that is deleted (on Mac OS
>> X). I see then the following error. Why does bash need to access the
>> current directory? Thanks.
>
> It's in order to set the PWD variable (which should always be available
> in the environment).
>
> --
> Seth David Schoen <schoen@loyalty.org>      |  Qué empresa fácil no pensar
>      http://www.loyalty.org/~schoen/        |  en un tigre, reflexioné.
>   8F08B027A5DB06ECF993B4660FD4F0CD2B11D2F9  |        -- Borges, "El Zahir"
>


-- 
Regards,
Peng



reply via email to

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