Skip to content

Instantly share code, notes, and snippets.

@guilhermegazzinelli
Last active February 14, 2023 13:01
Show Gist options
  • Save guilhermegazzinelli/008df5c9a9f6fc60a4ef786d8ef46b26 to your computer and use it in GitHub Desktop.
Save guilhermegazzinelli/008df5c9a9f6fc60a4ef786d8ef46b26 to your computer and use it in GitHub Desktop.
Bash Tricks

Passing arguments

  • Verify is Supplied any argument
  ((!$#)) && echo No arguments supplied! && exit 1
  • If you need to ensure a minimum ammount of args
  if [ $# -ge 3 ]
  then
    echo script has at least 3 arguments
  fi

In this case, if needed can use comparators (-eq, -lt, -ge, etc.) but only works for integer comparison For example:

  if [[ $# -eq 0 ]] ; then
    echo 'Must pass at least one argument'
    exit 1
  fi

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment