These might need to be broken into separate TILs for ease of navigation
A good cheat sheet can be found in this blog post
https://linuxize.com/post/how-to-check-if-string-contains-substring-in-bash/ https://www.baeldung.com/linux/string-contains-substring
https://www.grymoire.com/Unix/Quote.html
https://www.delftstack.com/howto/linux/split-string-in-bash/#using-ifs-to-split-a-string-in-bash
How can I declare and use Boolean variables in a shell script?
https://linuxize.com/post/bash-if-else-statement/
https://stackoverflow.com/questions/41893336/replace-empty-element-in-bash-array
If you observe the following error
Syntax error: redirection unexpected
It is due to your Bash script is being executing by a non-bash interpreter, e.g. sh
or similar.
You might have specified the shebang line in your shell script file:
#!/bin/bash
But if it is executed as:
sh myscript.sh
The shebang line is overridden by the interpreter specified on the command line.
I observed this issue in a Dockerfile
, where the entrypoint was specified as:
ENTRYPOINT ["/bin/sh", "/entrypoint.sh"]
So when I introduced more Bash in my entrypoint.sh
I was doomed. Changing the interpreter in the Dockerfile
fixed the issue.
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
Answer lifted from StackOverflow example lifted from rojopolis/spellcheck-github-actions. Do also see the reference Docker documentation