1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Make ~ expand to home directory after unsetting HOME

There was an issue with tilde expansion if the HOME var is unset.

	$ unset HOME
	$ echo ~
	martijn

Only the username is returned. Users are more likely to expect the
current user's home directory as configured in the OS.

POSIXly, the expansion of ~ is based on the value of HOME. If HOME
is unset, the results are unspecified. After unsetting HOME, in
bash, ~ returns the user's home directory as specified by the OS,
whereas in all other shells, ~ expands to the empty string. Only
ksh93 returns the username. The behaviour of bash is more useful.

Discussion:
https://github.com/ksh93/ksh/pull/225#issuecomment-799074107

src/cmd/ksh93/sh/macro.c,
src/cmd/ksh93/tests/tilde.sh:
- sh_tilde(): Backport fix by Mike Gilbert from ksh2020.
  See:	https://github.com/att/ast/issues/1391
	https://github.com/att/ast/pull/1396
	070d365d
- Add test.

src/cmd/ksh93/COMPATIBILITY:
- Note this change.
This commit is contained in:
Martijn Dekker 2021-03-15 21:49:02 +00:00
parent ef4fe4106c
commit 1df6a82a8a
5 changed files with 26 additions and 6 deletions

5
NEWS
View file

@ -3,6 +3,11 @@ For full details, see the git log at: https://github.com/ksh93/ksh
Any uppercase BUG_* names are modernish shell bug IDs.
2021-03-15:
- If the HOME variable is unset, the bare tilde ~ now expands to the current
user's system-configured home directory instead of merely the username.
2021-03-13:
- Fixed a file descriptor leak that occurred when ksh used /dev/fd for