github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/website/docs/configuration/functions/basename.html.md (about) 1 --- 2 layout: "functions" 3 page_title: "basename - Functions - Configuration Language" 4 sidebar_current: "docs-funcs-file-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 -> **Note:** This page is about Terraform 0.12 and later. For Terraform 0.11 and 13 earlier, see 14 [0.11 Configuration Language: Interpolation Syntax](../../configuration-0-11/interpolation.html). 15 16 `basename` takes a string containing a filesystem path and removes all except 17 the last portion from it. 18 19 This function works only with the path string and does not access the 20 filesystem itself. It is therefore unable to take into account filesystem 21 features such as symlinks. 22 23 If the path is empty then the result is `"."`, representing the current 24 working directory. 25 26 The behavior of this function depends on the host platform. On Windows systems, 27 it uses backslash `\` as the path segment separator. On Unix systems, the slash 28 `/` is used. 29 30 Referring directly to filesystem paths in resource arguments may cause 31 spurious diffs if the same configuration is applied from multiple systems or on 32 different host operating systems. We recommend using filesystem paths only 33 for transient values, such as the argument to [`file`](./file.html) (where 34 only the contents are then stored) or in `connection` and `provisioner` blocks. 35 36 ## Examples 37 38 ``` 39 > basename("foo/bar/baz.txt") 40 baz.txt 41 ``` 42 43 ## Related Functions 44 45 * [`dirname`](./dirname.html) returns all of the segments of a filesystem path 46 _except_ the last, discarding the portion that would be returned by 47 `basename`.