Timeline for Does ~ always equal $HOME
Current License: CC BY-SA 3.0
17 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Sep 13, 2018 at 18:21 | comment | added | Trevor Boyd Smith | great answer (concise (answers the question on the first line). through research and citations. clear writing. also talks about the deeper nuances.). Thanks! | |
| Oct 13, 2015 at 19:30 | comment | added | Michael Homer |
@cuonglm I checked the source code. It ultimately calls get_current_user_info, which uses getpwuid on all platforms but Tandem.
|
|
| Oct 13, 2015 at 18:01 | comment | added | cuonglm |
@MichaelHomer: As POSIX defined, the shell will use getpwnam(). Could you please give me any reference about bash behavior?
|
|
| Jul 26, 2014 at 7:35 | history | edited | Michael Homer | CC BY-SA 3.0 |
added 4 characters in body
|
| Jul 26, 2014 at 7:23 | comment | added | Stéphane Chazelas |
Note that bash before bash4 used to perform globbing upon tilde expansion (try HOME='/*' bash -c 'echo /*'). So HOME=/*; [ "$HOME" = ~ ] would return an error there.
|
|
| Jul 26, 2014 at 7:18 | history | edited | Michael Homer | CC BY-SA 3.0 |
added 4 characters in body
|
| Jul 26, 2014 at 7:03 | history | edited | Michael Homer | CC BY-SA 3.0 |
added 720 characters in body
|
| Jul 26, 2014 at 6:57 | comment | added | Stéphane Chazelas |
See there. Solaris /bin/sh before Solaris 11 was the Bourne shell, not a POSIX shell. The POSIX sh was in /usr/xpg4/bin or /usr/xpg6/bin. POSIX doesn't specify the path of its sh.
|
|
| Jul 26, 2014 at 6:56 | history | edited | Michael Homer | CC BY-SA 3.0 |
added 720 characters in body
|
| Jul 26, 2014 at 6:55 | comment | added | Stéphane Chazelas |
In a few shells including bash, if HOME is unset, ~ expands to the home directory of the user from the passwd database. So that's a case where ~ may not expand to the value of $HOME.
|
|
| Jul 26, 2014 at 6:54 | comment | added | Michael Homer |
Do you have a reference for that? It's not part of the command language or sh's description, and at least one version of sh I have access to doesn't support it (Solaris).
|
|
| Jul 26, 2014 at 6:53 | comment | added | Stéphane Chazelas |
[ ~ = $HOME ] can be false without a syntax error with values of $HOME like /a -a a = a. Leaving $HOME unquoted in that context doesn't make any sense.
|
|
| Jul 26, 2014 at 6:50 | comment | added | Stéphane Chazelas |
You also need to quote $HOME in [[ xx = $HOME ]] in ksh and bash as otherwise it's considered as a pattern (so the above would return false for a value of HOME like /[a])
|
|
| Jul 26, 2014 at 6:49 | history | edited | Michael Homer | CC BY-SA 3.0 |
added 720 characters in body
|
| Jul 26, 2014 at 6:47 | comment | added | Stéphane Chazelas |
POSIX specifies ~. ~ was not in the Thomson or Bourne shell (that in their time were available as /bin/sh). It's not in rc or its derivatives (where it's used for something else)
|
|
| Jul 26, 2014 at 5:38 | comment | added | Basile Starynkevitch |
However, /bin/sh might not be bash. I'm not sure that Posix sh specification tells about ~
|
|
| Jul 26, 2014 at 3:18 | history | answered | Michael Homer | CC BY-SA 3.0 |