github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/job-specification/hcl2/functions/file/pathexpand.mdx (about)

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