Skip to main content
pathexpand(path) replaces a leading ~ with the current user’s home directory. If path does not start with ~, it is returned unchanged.

Signature

Example

Allow users to provide a path using ~ notation for their personal configuration or credential files:
~/.kube/config becomes /home/user/.kube/config (or the platform equivalent).

Notes

  • Only a leading ~ is expanded. ~/some/path is supported. some~/path and ~user/path are not.
  • pathexpand reads the user’s home directory from the environment. On most systems this is $HOME on Linux and macOS, and %USERPROFILE% on Windows.