←back to thread

80 points Deeg9rie9usi | 4 comments | | HN request time: 0.786s | source
1. chubot ◴[] No.44381542[source]
Wow great bug!

> Bash forgot to reset errno before the call. For about 30 years, no one noticed

I have to say, this part of the POSIX API is maddening!

99% of the time, you don't need to set errno = 0 before making a call. You check for a non-zero return, and only then look at errno.

But SOMETIMES you need to set errno = 0, because in this case readdir() returns NULL on both error and EOF.

I actually didn't realize this before working on https://oils.pub/

---

And it should go without saying: Oils simply uses libc - we don't need to support system with a broken getcwd()!

Although a funny thing is that I just fixed a bug related to $PWD that AT&T ksh (the original shell, that bash is based on) hasn't fixed for 30+ years too!

(and I didn't realize it was still maintained)

https://www.illumos.org/issues/17442

https://github.com/oils-for-unix/oils/issues/2058

There is a subtle issue with respect to:

1) "trusting" the $PWD value you inherit from another process

2) Respecting symlinks - this is the reason the shell can't just call getcwd() !

    if (*p != '/' || stat(p, &st1) || stat(".", &st2) ||
        st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino)
        p = 0;
Basically, the shell considers BOTH the inherited $PWD and the value of getcwd() to determine its $PWD. It can't just use one or the other!
replies(2): >>44385123 #>>44387855 #
2. JdeBP ◴[] No.44385123[source]
The Bourne Again shell is not based upon the Korn shell. There's a very big clue in its name which prior shell the Bourne Again shell started out to clone. (-:
replies(1): >>44387041 #
3. chubot ◴[] No.44387041[source]
I'm saying the behavior of bash is largely based on ksh. See

https://pages.oils.pub/spec-compat/2025-06-19/renamed-tmp/sp...

(which I created)

Even the upcoming bash 5.4 implement ksh command sub ${ echo hi; }, which is more evidence that bash is based on ksh.

They're still implementing ksh 35 years later ...

4. alganet ◴[] No.44387855[source]
> and I didn't realize it was still maintained

ksh _was_ unmaintained for ages. It stopped effectively in 2012, with some very small attempts at reviving it in 2016, 2018 and 2020.

Then it was picked up for active development in 2021, and it lives here now:

https://github.com/ksh93/ksh

If you didn't already, you should open an issue there with your findings.

--

Shameless plug: I keep some docker images with all those versions for testing, and many other shells too both historical and active (including osh!)

https://github.com/alganet/shell-versions/blob/main/.github/...