Skip to content

Instantly share code, notes, and snippets.

@squioc
Created August 5, 2012 21:48
Show Gist options
  • Save squioc/3267248 to your computer and use it in GitHub Desktop.
Save squioc/3267248 to your computer and use it in GitHub Desktop.
[BASH] check the number of function parameters
#!/bin/bash
# -*- coding: UTF8 -*-
function usage() {
echo "$(basename ${0}) <first_arg> <second_arg>";
echo "";
echo "<first_arg> the first argument";
echo "<second_arg> the second argument";
}
function main() {
shift;
local first="${1}";
local second="${2}";
echo "first: $first"
echo "second: $second";
}
ARGC="${#}";
ARGV="${@}";
function run_with_at_least() {
[ $4 -ge $1 ] && $2 $4 $5 || $3;
}
run_with_at_least 2 "main" "usage" $ARGC "$ARGV"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment