Frequently Google'd bash snippets. I don't use these often enough to have them memorized.
add #!/bin/bash to the top of bash scripts or else you can run them with bash [filename].sh
- see For Loops
if [ ! -d "node_modules" ]; then
echo "node_modules directory exists"
fiarray=( one two three )
for i in "${array[@]}"
do
echo $i
done
# one
# two
# treeFOO="bar"
BAZ="${FOO}baz"
echo "${BAZ}"
# barbaz- don't add spaces before/after
equal, it will throw an error
while read line
do
echo "${line}"
if [[ "$line" =~ "$LINT_DIR" ]]; then
BUILD_RULES=true
break
fi
done < "${1:-/dev/stdin}"- can't set
stdinas a var!