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:
parent
ef4fe4106c
commit
1df6a82a8a
5 changed files with 26 additions and 6 deletions
|
@ -87,4 +87,12 @@ chmod +x $tmp/tilde
|
|||
nl=$'\n'
|
||||
[[ $($tmp/tilde foo) == "$PWD$nl$PWD" ]] 2> /dev/null || err_exit 'tilde fails inside a script run by name'
|
||||
|
||||
# ======
|
||||
# After unsetting HOME, ~ should expand to the current user's OS-configured home directory.
|
||||
unset HOME
|
||||
got=~
|
||||
[[ $got == /* && -d $got ]] || err_exit "expansion of bare tilde breaks after unsetting HOME (value: $(printf %q "$got"))"
|
||||
HOME=$tmp
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue