I had a situation where I had to make sure a sed
expression would apply
correctly on a file, but I did not want to change the file, and to also test
with various inputs.
To achieve that, I can use echo
to simulate the various inputs, and pipe it
to sed then. E.g.:
echo 'tag: latest' | sed -e "s/tag\: *.*/tag\: $(cat VERSION | tr -s '\n' ' ')/g"
echo 'tag: ' | sed -e "s/tag\: *.*/tag\: $(cat VERSION | tr -s '\n' ' ')/g"
echo 'tag:' | sed -e "s/tag\: *.*/tag\: $(cat VERSION | tr -s '\n' ' ')/g"
echo 'tag: xxx ' | sed -e "s/tag\: *.*/tag\: $(cat VERSION | tr -s '\n' ' ')/g"
echo 'tag: 0.11 ' | sed -e "s/tag\: *.*/tag\: $(cat VERSION | tr -s '\n' ' ')/g"