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
F151254210: D50974.id157435.diff
Tue, Apr 7, 3:36 AM
Unknown Object (File)
Fri, Mar 27, 6:49 AM
Unknown Object (File)
Thu, Mar 26, 1:46 AM
Unknown Object (File)
Thu, Mar 19, 3:54 AM
Unknown Object (File)
Wed, Mar 18, 11:47 PM
Unknown Object (File)
Mon, Mar 9, 2:52 PM
Unknown Object (File)
Mar 7 2026, 1:25 AM
Unknown Object (File)
Jan 31 2026, 1:21 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