how to expand ~ in a filepath

Hello, I am trying to open and read the content of this kind of filepath. ~/debian/changelog So is there a prefered way to expand the ~ into the real $HOME. thanks for your help Frédéric Classification de confidentialité SOLEIL Ce message et ses pièces jointes peuvent contenir des informations soumises à des règles de diffusion : * P (Public) : Diffusion libre y compris à l'extérieur de SOLEIL. * I (Interne) : Diffusion libre au sein de SOLEIL, ne doit pas être communiqué à l’extérieur sauf mention spécifique. * C (Confidentiel) : Diffusion restreinte aux personnes autorisées, internes ou externes. Le partage nécessite l'accord de la hiérarchie. * S (Sensible) : Accès restreint aux seuls destinataires. Partage non autorisé. Les informations contenues dans cet e-mail sont la propriété de SOLEIL. Si vous n'êtes pas le destinataire prévu, merci de nous en notifier et de ne pas utiliser, copier ou distribuer les informations qu'il contient.

Hello, unfortunately there is no "expandHomePath" or "realpath" helpers in the standard libraries. Searching for "FilePath -> IO FilePath" in hoogle shows an implementation in the hledger project: https://hackage-content.haskell.org/package/hledger-lib-1.43.2/docs/Hledger-... … which check if the path begins with "~/", and replace that with the output of "getHomeDirectory" -Tristan On Mon, Jul 21, 2025 at 07:19 PICCA Frederic-Emmanuel wrote:
Hello, I am trying to open and read the content of this kind of filepath.
~/debian/changelog
So is there a prefered way to expand the ~ into the real $HOME.
thanks for your help
Frédéric
Classification de confidentialité SOLEIL
Ce message et ses pièces jointes peuvent contenir des informations soumises à des règles de diffusion :
* P (Public) : Diffusion libre y compris à l'extérieur de SOLEIL. * I (Interne) : Diffusion libre au sein de SOLEIL, ne doit pas être communiqué à l’extérieur sauf mention spécifique. * C (Confidentiel) : Diffusion restreinte aux personnes autorisées, internes ou externes. Le partage nécessite l'accord de la hiérarchie. * S (Sensible) : Accès restreint aux seuls destinataires. Partage non autorisé.
Les informations contenues dans cet e-mail sont la propriété de SOLEIL. Si vous n'êtes pas le destinataire prévu, merci de nous en notifier et de ne pas utiliser, copier ou distribuer les informations qu'il contient. _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

There's also https://github.com/xmonad/xmonad-contrib/blob/master/XMonad/Prelude.hs#L135-... although it also does a few other things. On Mon, Jul 21, 2025 at 7:57 AM Tristan Cacqueray via Haskell-Cafe < haskell-cafe@haskell.org> wrote:
Hello, unfortunately there is no "expandHomePath" or "realpath" helpers in the standard libraries. Searching for "FilePath -> IO FilePath" in hoogle shows an implementation in the hledger project:
https://hackage-content.haskell.org/package/hledger-lib-1.43.2/docs/Hledger-...
… which check if the path begins with "~/", and replace that with the output of "getHomeDirectory"
-Tristan
On Mon, Jul 21, 2025 at 07:19 PICCA Frederic-Emmanuel wrote:
Hello, I am trying to open and read the content of this kind of filepath.
~/debian/changelog
So is there a prefered way to expand the ~ into the real $HOME.
thanks for your help
Frédéric
Classification de confidentialité SOLEIL
Ce message et ses pièces jointes peuvent contenir des informations soumises à des règles de diffusion :
* P (Public) : Diffusion libre y compris à l'extérieur de SOLEIL. * I (Interne) : Diffusion libre au sein de SOLEIL, ne doit pas être communiqué à l’extérieur sauf mention spécifique. * C (Confidentiel) : Diffusion restreinte aux personnes autorisées, internes ou externes. Le partage nécessite l'accord de la hiérarchie. * S (Sensible) : Accès restreint aux seuls destinataires. Partage non autorisé.
Les informations contenues dans cet e-mail sont la propriété de SOLEIL. Si vous n'êtes pas le destinataire prévu, merci de nous en notifier et de ne pas utiliser, copier ou distribuer les informations qu'il contient. _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- brandon s allbery kf8nh allbery.b@gmail.com

But it's not just ~/ that should be expanded.
All four of "~" "~/bar" "~foo" and "~foo/bar" should be expanded by a
tilde-expander.
On Tue, 22 Jul 2025 at 03:06, Brandon Allbery
There's also https://github.com/xmonad/xmonad-contrib/blob/master/XMonad/Prelude.hs#L135-... although it also does a few other things.
On Mon, Jul 21, 2025 at 7:57 AM Tristan Cacqueray via Haskell-Cafe
wrote: Hello, unfortunately there is no "expandHomePath" or "realpath" helpers in the standard libraries. Searching for "FilePath -> IO FilePath" in hoogle shows an implementation in the hledger project: https://hackage-content.haskell.org/package/hledger-lib-1.43.2/docs/Hledger-...
… which check if the path begins with "~/", and replace that with the output of "getHomeDirectory"
-Tristan
On Mon, Jul 21, 2025 at 07:19 PICCA Frederic-Emmanuel wrote:
Hello, I am trying to open and read the content of this kind of filepath.
~/debian/changelog
So is there a prefered way to expand the ~ into the real $HOME.
thanks for your help
Frédéric
Classification de confidentialité SOLEIL
Ce message et ses pièces jointes peuvent contenir des informations soumises à des règles de diffusion :
* P (Public) : Diffusion libre y compris à l'extérieur de SOLEIL. * I (Interne) : Diffusion libre au sein de SOLEIL, ne doit pas être communiqué à l’extérieur sauf mention spécifique. * C (Confidentiel) : Diffusion restreinte aux personnes autorisées, internes ou externes. Le partage nécessite l'accord de la hiérarchie. * S (Sensible) : Accès restreint aux seuls destinataires. Partage non autorisé.
Les informations contenues dans cet e-mail sont la propriété de SOLEIL. Si vous n'êtes pas le destinataire prévu, merci de nous en notifier et de ne pas utiliser, copier ou distribuer les informations qu'il contient. _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- brandon s allbery kf8nh allbery.b@gmail.com _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

There is no “should” here. It might be what you want, but it's not a universal standard. In Bash, “~foo” is not expanded. Sent from my iPad
On 2025. Jul 22., at 15:13, Richard O'Keefe
wrote: But it's not just ~/ that should be expanded. All four of "~" "~/bar" "~foo" and "~foo/bar" should be expanded by a tilde-expander.
On Tue, 22 Jul 2025 at 03:06, Brandon Allbery
wrote: There's also https://github.com/xmonad/xmonad-contrib/blob/master/XMonad/Prelude.hs#L135-... although it also does a few other things.
On Mon, Jul 21, 2025 at 7:57 AM Tristan Cacqueray via Haskell-Cafe
wrote: Hello, unfortunately there is no "expandHomePath" or "realpath" helpers in the standard libraries. Searching for "FilePath -> IO FilePath" in hoogle shows an implementation in the hledger project: https://hackage-content.haskell.org/package/hledger-lib-1.43.2/docs/Hledger-...
… which check if the path begins with "~/", and replace that with the output of "getHomeDirectory"
-Tristan
On Mon, Jul 21, 2025 at 07:19 PICCA Frederic-Emmanuel wrote:
Hello, I am trying to open and read the content of this kind of filepath.
~/debian/changelog
So is there a prefered way to expand the ~ into the real $HOME.
thanks for your help
Frédéric
Classification de confidentialité SOLEIL
Ce message et ses pièces jointes peuvent contenir des informations soumises à des règles de diffusion :
* P (Public) : Diffusion libre y compris à l'extérieur de SOLEIL. * I (Interne) : Diffusion libre au sein de SOLEIL, ne doit pas être communiqué à l’extérieur sauf mention spécifique. * C (Confidentiel) : Diffusion restreinte aux personnes autorisées, internes ou externes. Le partage nécessite l'accord de la hiérarchie. * S (Sensible) : Accès restreint aux seuls destinataires. Partage non autorisé.
Les informations contenues dans cet e-mail sont la propriété de SOLEIL. Si vous n'êtes pas le destinataire prévu, merci de nous en notifier et de ne pas utiliser, copier ou distribuer les informations qu'il contient. _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- brandon s allbery kf8nh allbery.b@gmail.com _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

With GNU bash, version 5.2.37(1)-release, `~foo` (provided that foo is a user) is indeed expanded to the user's home directory. Cheers, Hécate Le 22/07/2025 à 14:17, Mig Mit a écrit :
There is no “should” here. It might be what you want, but it's not a universal standard. In Bash, “~foo” is not expanded.
Sent from my iPad
On 2025. Jul 22., at 15:13, Richard O'Keefe
wrote: But it's not just ~/ that should be expanded. All four of "~" "~/bar" "~foo" and "~foo/bar" should be expanded by a tilde-expander.
On Tue, 22 Jul 2025 at 03:06, Brandon Allbery
wrote: There's also https://github.com/xmonad/xmonad-contrib/blob/master/XMonad/Prelude.hs#L135-... although it also does a few other things.
On Mon, Jul 21, 2025 at 7:57 AM Tristan Cacqueray via Haskell-Cafe
wrote: Hello, unfortunately there is no "expandHomePath" or "realpath" helpers in the standard libraries. Searching for "FilePath -> IO FilePath" in hoogle shows an implementation in the hledger project: https://hackage-content.haskell.org/package/hledger-lib-1.43.2/docs/Hledger-...
… which check if the path begins with "~/", and replace that with the output of "getHomeDirectory"
-Tristan
On Mon, Jul 21, 2025 at 07:19 PICCA Frederic-Emmanuel wrote:
Hello, I am trying to open and read the content of this kind of filepath.
~/debian/changelog
So is there a prefered way to expand the ~ into the real $HOME.
thanks for your help
Frédéric
Classification de confidentialité SOLEIL
Ce message et ses pièces jointes peuvent contenir des informations soumises à des règles de diffusion :
* P (Public) : Diffusion libre y compris à l'extérieur de SOLEIL. * I (Interne) : Diffusion libre au sein de SOLEIL, ne doit pas être communiqué à l’extérieur sauf mention spécifique. * C (Confidentiel) : Diffusion restreinte aux personnes autorisées, internes ou externes. Le partage nécessite l'accord de la hiérarchie. * S (Sensible) : Accès restreint aux seuls destinataires. Partage non autorisé.
Les informations contenues dans cet e-mail sont la propriété de SOLEIL. Si vous n'êtes pas le destinataire prévu, merci de nous en notifier et de ne pas utiliser, copier ou distribuer les informations qu'il contient. _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- brandon s allbery kf8nh allbery.b@gmail.com _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- Hécate ✨ 🐦: @TechnoEmpress IRC: Hecate WWW: https://glitchbra.in RUN: BSD

No need to refer to current versions. Per https://en.wikipedia.org/wiki/Tilde and other resources, this was introduced in the 1970s. Now whether some shells don't expand it, it's another question. Gemini/Google AI search even claims that it is part of the POSIX standard, I don't know if that's true. More fun resources: https://dave.cheney.net/2017/08/21/the-here-is-key :) regards, iustin On 2025-07-22 14:23:04, Hécate via Haskell-Cafe wrote:
With GNU bash, version 5.2.37(1)-release, `~foo` (provided that foo is a user) is indeed expanded to the user's home directory.
Cheers, Hécate
Le 22/07/2025 à 14:17, Mig Mit a écrit :
There is no “should” here. It might be what you want, but it's not a universal standard. In Bash, “~foo” is not expanded.
Sent from my iPad
On 2025. Jul 22., at 15:13, Richard O'Keefe
wrote: But it's not just ~/ that should be expanded. All four of "~" "~/bar" "~foo" and "~foo/bar" should be expanded by a tilde-expander.
On Tue, 22 Jul 2025 at 03:06, Brandon Allbery
wrote: There's also https://github.com/xmonad/xmonad-contrib/blob/master/XMonad/Prelude.hs#L135-... although it also does a few other things.
On Mon, Jul 21, 2025 at 7:57 AM Tristan Cacqueray via Haskell-Cafe
wrote: Hello, unfortunately there is no "expandHomePath" or "realpath" helpers in the standard libraries. Searching for "FilePath -> IO FilePath" in hoogle shows an implementation in the hledger project: https://hackage-content.haskell.org/package/hledger-lib-1.43.2/docs/Hledger-...
… which check if the path begins with "~/", and replace that with the output of "getHomeDirectory"
-Tristan
On Mon, Jul 21, 2025 at 07:19 PICCA Frederic-Emmanuel wrote:
Hello, I am trying to open and read the content of this kind of filepath.
~/debian/changelog
So is there a prefered way to expand the ~ into the real $HOME.
thanks for your help
Frédéric
Classification de confidentialité SOLEIL
Ce message et ses pièces jointes peuvent contenir des informations soumises à des règles de diffusion :
* P (Public) : Diffusion libre y compris à l'extérieur de SOLEIL. * I (Interne) : Diffusion libre au sein de SOLEIL, ne doit pas être communiqué à l’extérieur sauf mention spécifique. * C (Confidentiel) : Diffusion restreinte aux personnes autorisées, internes ou externes. Le partage nécessite l'accord de la hiérarchie. * S (Sensible) : Accès restreint aux seuls destinataires. Partage non autorisé.
Les informations contenues dans cet e-mail sont la propriété de SOLEIL. Si vous n'êtes pas le destinataire prévu, merci de nous en notifier et de ne pas utiliser, copier ou distribuer les informations qu'il contient. _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- brandon s allbery kf8nh allbery.b@gmail.com _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- Hécate ✨ 🐦: @TechnoEmpress IRC: Hecate WWW: https://glitchbra.in RUN: BSD
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

On 22.07.25 14:30, Iustin Pop wrote:
Gemini/Google AI search even claims that it is part of the POSIX standard, I don't know if that's true.
It is. See https://pubs.opengroup.org/onlinepubs/009604499/utilities/xcu_chap02.html#ta... . It says that ~ is the current user's home directory, ~blub is the "blub" users's home directory, or undefined if no "blub" user exists on the system. It does not say what should happen if the user is present but does not have a home directory assigned.

On Tue, Jul 22, 2025 at 02:23:04PM +0200, Hécate via Haskell-Cafe wrote:
With GNU bash, version 5.2.37(1)-release, `~foo` (provided that foo is a user) is indeed expanded to the user's home directory.
Ditto in "zsh" (largely bash-compatible) on MacOS: % echo ~/Library /Users/viktor/Library % echo ~admin/Library /Users/admin/Library And both /bin/sh and /bin/csh on NetBSD: $ echo ~root/.profile ~postfix/public /root/.profile /var/spool/postfix/public So "~" expansion is quite common in modern Unix shells. -- Viktor. 🇺🇦 Слава Україні!

Where do you get the idea that Bash does not expand ~foo?
<transcript>
pc@Boole ~/Downloads
$ echo $SHELL
/bin/bash
pc@Boole ~/Downloads
$ echo ~pc
/home/pc
</transcript>
Bash Reference Manual section 3.5.2 begins with this paragraph:
<quote>
If a word begins with an unquoted tilde character (‘~’), all of the
characters up to the first unquoted slash (or all characters, if there
is no unquoted slash) are considered a tilde-prefix. If none of the
characters in the tilde-prefix are quoted, the characters in the
tilde-prefix following the tilde are treated as a possible login name.
If this login name is the null string, the tilde is replaced with the
value of the HOME shell variable. If HOME is unset, the tilde expands
to the home directory of the user executing the shell instead.
Otherwise, the tilde-prefix is replaced with the home directory
associated with the specified login name.
</quote>
Section 2.6.1 of the POSIX.1 shell specification describes tilde
expansion, and very explicitly requires that
<quote>
the characters in the tilde-prefix following the <tilde> shall be
treated as a possible login name from the user database
</quote>
so it actually *is* a standard.
In fact in something like
pongpath=~foo:~bar:~ugh
*each* of the three tildes begins a multicharacter tilde prefix.
On Wed, 23 Jul 2025 at 00:18, Mig Mit
There is no “should” here. It might be what you want, but it's not a universal standard. In Bash, “~foo” is not expanded.
Sent from my iPad
On 2025. Jul 22., at 15:13, Richard O'Keefe
wrote: But it's not just ~/ that should be expanded. All four of "~" "~/bar" "~foo" and "~foo/bar" should be expanded by a tilde-expander.
On Tue, 22 Jul 2025 at 03:06, Brandon Allbery
wrote: There's also https://github.com/xmonad/xmonad-contrib/blob/master/XMonad/Prelude.hs#L135-... although it also does a few other things.
On Mon, Jul 21, 2025 at 7:57 AM Tristan Cacqueray via Haskell-Cafe
wrote: Hello, unfortunately there is no "expandHomePath" or "realpath" helpers in the standard libraries. Searching for "FilePath -> IO FilePath" in hoogle shows an implementation in the hledger project: https://hackage-content.haskell.org/package/hledger-lib-1.43.2/docs/Hledger-...
… which check if the path begins with "~/", and replace that with the output of "getHomeDirectory"
-Tristan
On Mon, Jul 21, 2025 at 07:19 PICCA Frederic-Emmanuel wrote:
Hello, I am trying to open and read the content of this kind of filepath.
~/debian/changelog
So is there a prefered way to expand the ~ into the real $HOME.
thanks for your help
Frédéric
Classification de confidentialité SOLEIL
Ce message et ses pièces jointes peuvent contenir des informations soumises à des règles de diffusion :
* P (Public) : Diffusion libre y compris à l'extérieur de SOLEIL. * I (Interne) : Diffusion libre au sein de SOLEIL, ne doit pas être communiqué à l’extérieur sauf mention spécifique. * C (Confidentiel) : Diffusion restreinte aux personnes autorisées, internes ou externes. Le partage nécessite l'accord de la hiérarchie. * S (Sensible) : Accès restreint aux seuls destinataires. Partage non autorisé.
Les informations contenues dans cet e-mail sont la propriété de SOLEIL. Si vous n'êtes pas le destinataire prévu, merci de nous en notifier et de ne pas utiliser, copier ou distribuer les informations qu'il contient. _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- brandon s allbery kf8nh allbery.b@gmail.com _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
participants (9)
-
Brandon Allbery
-
Hécate
-
Iustin Pop
-
jo@durchholz.org
-
Mig Mit
-
PICCA Frederic-Emmanuel
-
Richard O'Keefe
-
Tristan Cacqueray
-
Viktor Dukhovni