Reputation: 741
I'll go straight to an example:
docker run --rm -i alpine /bin/sh -vs <<EOF
echo BEFORE
cat /etc/*elease
echo AFTER
EOF
Output:
echo BEFORE
cat /etc/*elease
echo AFTER
BEFORE
3.9.3
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.9.3
PRETTY_NAME="Alpine Linux v3.9"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://bugs.alpinelinux.org/"
AFTER
Note that commands itself (like echo BEFORE
) printed by sh -v
appear before any command output (like BEFORE
).
I would expect to see
echo BEFORE
BEFORE
cat /etc/*elease
3.9.3
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.9.3
PRETTY_NAME="Alpine Linux v3.9"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://bugs.alpinelinux.org/"
echo AFTER
AFTER
I tried using stdbuf
and script
as for example described here, but to no avail.
I don't think I am the only one who has this problem. So I wonder
Upvotes: 0
Views: 586
Reputation: 741
I was able to solve this problem by redirecting stdout to stderr:
docker run --rm -i alpine /bin/sh -vs <<EOF
exec 1>&2
echo BEFORE
cat /etc/*elease
echo AFTER
EOF
Upvotes: 1