til

Today I Learned: collection of notes, tips and tricks and stuff I learn from day to day working with computers and technology as an open source contributor and product manager

View project on GitHub

Use bash

These might need to be broken into separate TILs for ease of navigation

A good cheat sheet can be found in this blog post

Find Substrings in Bash

https://linuxize.com/post/how-to-check-if-string-contains-substring-in-bash/ https://www.baeldung.com/linux/string-contains-substring

Quotes

https://www.grymoire.com/Unix/Quote.html

error conditional binary operator expected in compound branch

https://unix.stackexchange.com/questions/435193/error-conditional-binary-operator-expected-in-compound-branch

Split Strings

https://www.delftstack.com/howto/linux/split-string-in-bash/#using-ifs-to-split-a-string-in-bash

Use Booleans

How can I declare and use Boolean variables in a shell script?

Bash if, then, else

https://linuxize.com/post/bash-if-else-statement/

Handle empty element in array

https://stackoverflow.com/questions/41893336/replace-empty-element-in-bash-array

Syntax error: redirection unexpected

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