DEV Community

Brandon Rozek
Brandon Rozek

Posted on • Originally published at brandonrozek.com on

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

Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay