Skip to content

Instantly share code, notes, and snippets.

@robballou
Last active January 9, 2018 20:38
Show Gist options
  • Save robballou/b40673598ea6ce56963fbf9d43a33879 to your computer and use it in GitHub Desktop.
Save robballou/b40673598ea6ce56963fbf9d43a33879 to your computer and use it in GitHub Desktop.
Bash examples for my own memory's sake...
#!/bin/bash
# check number of arguments, output a message to STDERR
if [[ "$#" -eq "0" ]]; then
2>&1 echo "Usage: $0 FILE"
exit 1
fi
# check if an argument equals a string
if [[ "$1" = "dev" ]]; then
# ...
fi
# one line if...
if [[ "$1" = "dev" ]]; then echo "If"; else echo "Else"; fi
# arrays and looping over them
repos=(example1 example2)
for repo in "${repos[@]}"; do
echo $repo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment