github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/website/content/docs/job-specification/hcl2/functions/file/pathexpand.mdx (about) 1 --- 2 layout: docs 3 page_title: pathexpand - Functions - Configuration Language 4 sidebar_title: pathexpand 5 description: |- 6 The pathexpand function expands a leading ~ character to the current user's 7 home directory. 8 --- 9 10 # `pathexpand` Function 11 12 `pathexpand` takes a filesystem path that might begin with a `~` segment, 13 and if so it replaces that segment with the current user's home directory 14 path. 15 16 This function works only with the path string and does not access the 17 filesystem itself. It is therefore unable to take into account filesystem 18 features such as symlinks. 19 20 If the leading segment in the path is not `~` then the given path is returned 21 unmodified. 22 23 Using this function in job arguments will cause spurious diffs if the 24 same configuration is run by multiple users with different home directory 25 paths, or used on different host operating systems. 26 27 The rules for determining the "home directory" for the current user vary 28 depending on host operating system. 29 30 **For Unix systems**, the following sources are consulted, in order of preference: 31 32 - The `HOME` environment variable. 33 - The result of running `getent passwd` followed by the Nomad process uid. 34 - The result of running `cd && pwd` in `sh`. 35 36 **For Windows systems**, there is not really the concept of a home directory 37 in the same sense as on Unix, but the following sources are consulted in 38 order of preference: 39 40 - The `HOME` environment variable. 41 - The `HOMEDRIVE` and `HOMEPATH` environment variables, if both are set. 42 - The `USERPROFILE` environment variable. 43 44 The exact rules employed for each operating system may change in future 45 releases of Nomad. 46 47 ## Examples 48 49 ```shell-session 50 > pathexpand("~/.ssh/id_rsa") 51 /home/steve/.ssh/id_rsa 52 > pathexpand("/etc/resolv.conf") 53 /etc/resolv.conf 54 ```