I just want to check if one parameter was supplied in my bash script or not.
I found this, but all the solutions seem to be unnecessarily complicated.
What’s a simple solution to this simple problem that would make sense to a beginner?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
$#which is equal to the number of arguments supplied, e.g.:Word of caution: Note that inside a function this will equal the number of arguments supplied to the function rather than the script.
EDIT: As pointed out by SiegeX in bash you can also use arithmetic expressions in
(( ... )). This can be used like this: