Skip to content

Commit e57af0e

Browse files
committed
[v1.1] cd: avoid brackets in system error messages
The brackets in 'cd' errors have always slightly annoyed me: $ cd nonexistent -ksh: cd: nonexistent: [No such file or directory] After this commit, this looks more like other shells: $ cd nonexistent -ksh: cd: nonexistent: No such file or directory src/cmd/ksh93/bltins/cd_pwd.c: b_cd(): - To avoid errormsg() automatically adding the system error message within brackets, use ERROR_exit instead of ERROR_system. - Manually add the system error using strerror(errno) instead. This is not backported to 1.0 because it's not unheard of to grep error messages in script output, so it could be an incompatibility.
1 parent 98684cb commit e57af0e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Uppercase BUG_* IDs are shell bug IDs as used by the Modernish shell library.
1414
- correctly recognise a word that is quoted with the $'...' syntax,
1515
even when it includes a backslash-escaped single quote.
1616

17+
- [v1.1] The 'cd' command no longer adds brackets to system error messages.
18+
1719
2025-03-24:
1820

1921
- Fixed a crash that occurred in specific circumstances when processing a

src/cmd/ksh93/bltins/cd_pwd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ int b_cd(int argc, char *argv[],Shbltin_t *context)
260260
{
261261
if(saverrno)
262262
errno = saverrno;
263-
errormsg(SH_DICT,ERROR_system(ret),"%s:",dir);
263+
errormsg(SH_DICT,ERROR_exit(ret),"%s: %s",dir,strerror(errno));
264264
UNREACHABLE();
265265
}
266266
success:
@@ -272,7 +272,7 @@ int b_cd(int argc, char *argv[],Shbltin_t *context)
272272
if (!(dir=pathcanon(dir,PATH_PHYSICAL)))
273273
{
274274
dir = stkptr(sh.stk,PATH_OFFSET);
275-
errormsg(SH_DICT,ERROR_system(ret),"%s:",dir);
275+
errormsg(SH_DICT,ERROR_exit(ret),"%s: %s",dir,strerror(errno));
276276
UNREACHABLE();
277277
}
278278
stkseek(sh.stk,dir-stkptr(sh.stk,0));

0 commit comments

Comments
 (0)