Here-string is not POSIX compliant #1

Closed
opened 2026-04-10 12:38:39 +00:00 by TurtleException · 2 comments

Plain sh (POSIX compliant) does not support here-strings (<<<).

This loop will produce a syntax error:

Lines 15 to 18 in f14cdf3
while read tag; do
full_tag="$DOCKER_TAG_PREFIX$tag"
docker image tag "$IMAGE_ID" "$full_tag"
done <<< "$DOCKER_TAGS"

Plain `sh` (POSIX compliant) does not support here-strings (`<<<`). This loop will produce a syntax error: https://forge.turtle-host.de/actions/docker-build/src/commit/f14cdf3ca3277276e80510412be983e9d437f55b/src/docker-build.sh#L15-L18
Author
Owner

One possible fix would be something like this:

printf '%s\n' "$DOCKER_TAGS" | while read -r tag; do
    # ...
done

This has the disadvantage of running the loop in a subshell, which would make persistence of variables more complex (which will be required in the future to produce workflow outputs).

One possible fix would be something like this: ```sh printf '%s\n' "$DOCKER_TAGS" | while read -r tag; do # ... done ``` This has the disadvantage of running the loop in a subshell, which would make persistence of variables more complex (which will be required in the future to produce workflow outputs).
Author
Owner

According to this StackOverflow answer, the here-string could also be replaced by a here-document:

while read tag; do
    # ...
done << EOF
$DOCKER_TAGS
EOF

But honestly - it looks kinda weird. Doesn't really matter for functionality, I just don't like it.
I have not yet tested how this would behave with newlines.

According to [this StackOverflow answer](https://stackoverflow.com/a/26849692), the here-string could also be replaced by a here-document: ```sh while read tag; do # ... done << EOF $DOCKER_TAGS EOF ``` But honestly - it looks kinda weird. Doesn't really matter for functionality, I just don't like it. I have not yet tested how this would behave with newlines.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
actions/docker-build#1
No description provided.