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/pathis supported.some~/pathand~user/pathare not. pathexpandreads the user’s home directory from the environment. On most systems this is$HOMEon Linux and macOS, and%USERPROFILE%on Windows.