Jemsu Quartz

Search

Search IconIcon to open search

Shell Scripting

Last updated Mar 30, 2023 Edit Source

I always look up the same things again and again and/or refer to old scripts where I’ve done the looking up. Might as well start dumping some things here.

# Arrays

I think this is compatible with bash/zsh, but not sure. I tend to stick to bash for scripts for portability, just in case.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
packages=( ctop lazydocker )

for i in "${packages[@]}"
do
  echo "Checking if $i is available..."
  if [ -x "$(command -v $i)" ]; then
    echo "Found $i"
  else
    brew install $i
  fi
done

# Case

1
2
3
4
5
6
7
8
9
case expression in
    pattern1 )
        statements 
    ;;
    pattern2 )
        statements
    ;;
    ...
esac