I am trying to write a script that mimics cp where there is a source and destination input. How can I count the number of arguments given on the command line?
For example:
./myscript src dest
How can I check that at least 2 things were given?
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 the
$#special variable. Its value is the number of arguments. So if you have a script that contains only:and execute it like this:
It’ll print 4.
In your case you may want to do something like: