mirror of
https://github.com/Brandon-Rozek/website.git
synced 2024-10-30 01:12:07 -04:00
549 B
549 B
date | draft | medium_enabled | medium_post_id | tags | title | |
---|---|---|---|---|---|---|
2020-12-15 14:25:11 | false | true | ac38c9d9d896 |
|
Quick Bash: Check Argument Count |
I've been writing more bash scripts recently and I noticed that I often check for the number of arguments before validating them in my scripts. I'll share that small snippet here for my future self.
#!/bin/sh
set -o errexit
set -o nounset
set -o pipefail
show_usage() {
echo "Usage: script [arg1]"
exit 1
}
# Check argument count
if [ "$#" -ne 1 ]; then
show_usage
fi