Skip to content

Commit

Permalink
documentation for variable expansion
Browse files Browse the repository at this point in the history
Signed-off-by: Tristan Stenner <[email protected]>
  • Loading branch information
tstenner committed Sep 28, 2023
1 parent e4f0f53 commit 9451d8d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion frontend/dockerfile/docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,30 @@ modifiers as specified below:
will be that value. If `variable` is not set then `word` will be the result.
- `${variable:+word}` indicates that if `variable` is set then `word` will be
the result, otherwise the result is the empty string.
- `${variable#pattern}` will return the value of `variable` with the shortest
expansion of the pattern stripped from the beginning
- `${variable##pattern}` will return the value of `varaible` with the *longest*
expansion of the pattern stripped from the beginning,
e.g. for `sheep=baaah` the expression `${sheep#b*a}` will yield `h` rather
than `aah`.
- `${variable%pattern}` and `${variable%%pattern}` will strip from the end,
respectively.

In all cases, `word` can be any string, including additional environment
variables.

`pattern` can be a glob pattern where `?` will match any single character
and `*` any number of characters (including zero).

Escaping is possible by adding a `\` before the variable: `\$foo` or `\${foo}`,
for example, will translate to `$foo` and `${foo}` literals respectively.

Example (parsed representation is displayed after the `#`):

```dockerfile
FROM busybox
ARG IMAGE=busybox:latest
# FROM busybox:stable
FROM ${IMAGE%:*}:stable
ENV FOO=/bar
WORKDIR ${FOO} # WORKDIR /bar
ADD . $FOO # ADD . /bar
Expand Down

0 comments on commit 9451d8d

Please sign in to comment.