-1

If there's zeros or more than 2 inputs, a message will be shown to the user.

I don't have much idea of how to check, how many values have been passed from the command line. Can I get a simple program?

  • Possible duplicate of https://stackoverflow.com/questions/18568706/check-number-of-arguments-passed-to-a-bash-script – tripleee Nov 24 '17 at 21:28
  • Possible duplicate of https://stackoverflow.com/questions/806906/how-do-i-test-if-a-variable-is-a-number-in-bash – tripleee Nov 24 '17 at 21:28
  • 1
    Possible duplicate of [Check number of arguments passed to a Bash script](https://stackoverflow.com/questions/18568706/check-number-of-arguments-passed-to-a-bash-script) – PiedPiper Nov 25 '17 at 12:14

1 Answers1

0

Below is an example code which will return "no argument passed" if no argument is passed:

#!/bin/bash
if [ $# = 0 ];
then
echo "No argument is passed"
fi

Arguments is handled by bash with multiple option, below for your reference:

$#  is the number of parameters passed
$0  returns the name of the shell script running as well as its    location in the file system
$*  gives a single word containing all the parameters passed   to the script 
$@  gives an array of words containing all the parameters  passed to the script