I've been tracking down an issue I've been facing in a buildkite script, and here's what I've got:
Firstly, I enter the shell of a docker image:
docker run --rm -it --entrypoint bash node:12.21.0
This docker image doesn't have any text editors, so I create my shell scripts by concating to a file:
touch a.sh
chmod +x a.sh
printf '#!/bin/sh\necho ${1:0:1}' >> a.sh
touch b.sh
chmod +x b.sh
printf '#!/bin/bash\necho ${1:0:1}' >> b.sh
I now run my scripts:
./a.sh hello
>./a.sh: 2: ./a.sh: Bad substitution
./b.sh hello
>h
Can someone tell me in simple terms what the issue is here?
This AskUbuntu question says that bash and sh are different shells, and that in many systems sh will symlink to bash.
What's going on specifically on this docker image? How would I know?
docker exec IMAGE ls -l /bin/bash /bin/sh
. I suppose that the Bourne Shell doesn't know string substitution.