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
F168469663: D50974.id157435.diff
Fri, Aug 28, 1:38 PM
Unknown Object (File)
Thu, Aug 27, 8:07 PM
Unknown Object (File)
Wed, Aug 26, 4:10 AM
Unknown Object (File)
Mon, Aug 24, 9:13 AM
Unknown Object (File)
Mon, Aug 24, 2:45 AM
Unknown Object (File)
Mon, Aug 24, 12:21 AM
Unknown Object (File)
Fri, Aug 21, 8:58 AM
Unknown Object (File)
Sun, Aug 16, 8:02 AM
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