[Bug 287440] sh(1): cd "" shall result in error

From: <bugzilla-noreply_at_freebsd.org>
Date: Wed, 11 Jun 2025 04:20:22 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=287440

            Bug ID: 287440
           Summary: sh(1): cd "" shall result in error
           Product: Base System
           Version: 15.0-CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: standards
          Assignee: standards@FreeBSD.org
          Reporter: delphij@FreeBSD.org

POSIX says in
https://pubs.opengroup.org/onlinepubs/9799919799/utilities/cd.html , quote:

```
directory
[...]
If directory is an empty string, cd shall write a diagnostic message to
standard error and exit with non-zero status.
```

My interpretation is that this means in a shell script,

```
cd ""
```

shall result in an error.

The POSIX behavior would prevent a script that failed to check if an variable
was empty, for example, the following command:

cd "${WRKDIR}"

from avoiding an error that could otherwise be called out and have the code
logic corrected.

Historically, the outcome of the command was "undefined", therefore some shells
opt to issue an error (e.g. tcsh), and ours elects to do nothing.  Additional
discussion can be seen here: https://austingroupbugs.net/view.php?id=1047 .  I
think giving an error for `cd ""` is more reasonable because when the caller
asked to chdir, and it returned 0, then the caller should be able to assume
that the action was successful, and giving an empty string should result in
error.

-- 
You are receiving this mail because:
You are the assignee for the bug.