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

     1  ---
     2  layout: docs
     3  page_title: basename - Functions - Configuration Language
     4  sidebar_title: basename
     5  description: |-
     6    The basename function removes all except the last portion from a filesystem
     7    path.
     8  ---
     9  
    10  # `basename` Function
    11  
    12  `basename` takes a string containing a filesystem path and removes all except
    13  the last portion from it.
    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 path is empty then the result is `"."`, representing the job file directory.
    20  
    21  The behavior of this function depends on the host platform. On Windows systems,
    22  it uses backslash `\` as the path segment separator. On Unix systems, the slash
    23  `/` is used.
    24  
    25  Referring directly to filesystem paths in job arguments may cause
    26  spurious diffs if the same configuration is applied from multiple systems or on
    27  different host operating systems. We recommend using filesystem paths only
    28  for transient values, such as the argument to [`file`](/docs/job-specification/hcl2/functions/file/file) (where
    29  only the contents are then stored).
    30  
    31  ## Examples
    32  
    33  ```shell-session
    34  > basename("foo/bar/baz.txt")
    35  baz.txt
    36  ```
    37  
    38  ## Related Functions
    39  
    40  - [`dirname`](/docs/job-specification/hcl2/functions/file/dirname) returns all of the segments of a filesystem path
    41    _except_ the last, discarding the portion that would be returned by
    42    `basename`.