Variables as commands in Bash scripts

Simply don’t put whole commands in variables. You’ll get into a lot of trouble trying to recover quoted arguments. Also: Avoid using all-capitals variable names in scripts. It is an easy way to shoot yourself in the foot. Don’t use backquotes. Use $(…) instead; it nests better. #! /bin/bash if [ $# -ne 2 ] … Read more

Detect if PATH has a specific directory entry in it

Using grep is overkill, and can cause trouble if you’re searching for anything that happens to include RE metacharacters. This problem can be solved perfectly well with bash’s builtin [[ command: if [[ “:$PATH:” == *”:$HOME/bin:”* ]]; then echo “Your path is correctly set” else echo “Your path is missing ~/bin, you might want to … Read more