github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/website/content/docs/job-specification/hcl2/functions/file/dirname.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: dirname - Functions - Configuration Language
     4  sidebar_title: dirname
     5  description: The dirname function removes the last portion from a filesystem path.
     6  ---
     7  
     8  # `dirname` Function
     9  
    10  `dirname` takes a string containing a filesystem path and removes the last
    11  portion from it.
    12  
    13  This function works only with the path string and does not access the
    14  filesystem itself. It is therefore unable to take into account filesystem
    15  features such as symlinks.
    16  
    17  If the path is empty then the result is `"."`, representing the job file directory.
    18  
    19  The behavior of this function depends on the host platform. On Windows systems,
    20  it uses backslash `\` as the path segment separator. On Unix systems, the slash
    21  `/` is used. The result of this function is normalized, so on a Windows system
    22  any slashes in the given path will be replaced by backslashes before returning.
    23  
    24  Referring directly to filesystem paths in job arguments may cause
    25  spurious diffs if the same configuration is applied from multiple systems or on
    26  different host operating systems. We recommend using filesystem paths only
    27  for transient values, such as the argument to [`file`](/docs/job-specification/hcl2/functions/file/file) (where
    28  only the contents are then stored).
    29  
    30  ## Examples
    31  
    32  ```shell-session
    33  > dirname("foo/bar/baz.txt")
    34  foo/bar
    35  ```
    36  
    37  ## Related Functions
    38  
    39  - [`basename`](/docs/job-specification/hcl2/functions/file/basename) returns _only_ the last portion of a filesystem
    40    path, discarding the portion that would be returned by `dirname`.