[Haskell-cafe] how to expand ~ in a filepath

Viktor Dukhovni ietf-dane at dukhovni.org
Thu Jul 24 05:53:11 UTC 2025


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.  🇺🇦 Слава Україні!


More information about the Haskell-Cafe mailing list