Page MenuHomeFreeBSD

sh(1): Do not interpret chdir to "" as equivalent to chdir with no argument
ClosedPublic

Authored by delphij on Jun 23 2025, 8:04 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Sep 30, 9:49 PM
Unknown Object (File)
Mon, Sep 29, 12:15 AM
Unknown Object (File)
Sat, Sep 27, 4:42 PM
Unknown Object (File)
Fri, Sep 26, 11:16 PM
Unknown Object (File)
Tue, Sep 23, 7:29 PM
Unknown Object (File)
Wed, Sep 17, 2:06 PM
Unknown Object (File)
Sep 10 2025, 5:50 AM
Unknown Object (File)
Sep 8 2025, 6:56 PM
Subscribers

Details

Summary

A script that does the following:

cd "${dir}" || exit 1

would incorrectly remain in the current directory when ${dir} is
an empty string under the current implementation. This behavior,
while historical, is potentially dangerous, as it is likely not
what the script author intended.

Change the command to treat an empty string as an error and emit a
diagnostic message to standard error, as required by
IEEE Std 1003.1-2024.

PR: standards/287440

Test Plan

kyua test bin/sh

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable