Article 4WRW3 Bash logic combination to restrict a user to the required number of argument

Bash logic combination to restrict a user to the required number of argument

by
dan-german
from LinuxQuestions.org on (#4WRW3)
My bash function is suppose to ask for an argument when it is not supplied and indicate surplus argument when the argument supplied is more than three (3). But presently,when i supply it with 3 argument it does not echo "surplus argument" but give the same result with when i supply one or two argument. Please how do i correct this or is it from my bash logic combination?
below is the code:

#!/bin/bash

Variable1="$1"
Variable2="$2"

AddVariable () {

Variable1="$1"
Variable2="$2"

if [ "$#" -eq 0 ]
then
echo "provide an argument"

elif [ "$#" -ne 1 ] && [ "$#" -ne 2 ] || [ "$#" -eq 3 ]
then
echo "Surplus argument provided"
else

printname "$Variable1"
deletename "$Variable2"

fi

}

deletename(){

for file in $Variable/*;do

echo "$(rm -i "$file")"
echo "deleting $Variable"

done
}
printname(){
Variable=$1
for file in $Variable/*;do

echo "$(basename "$file")"
done
}

#printname "$Variable1"
#deletename "$Variable2"
AddVariable $Variable1 $Variable2latest?d=yIl2AUoC8zA latest?i=GBvV9v2aHm8:sy_lNmVREqk:F7zBnMy latest?i=GBvV9v2aHm8:sy_lNmVREqk:V_sGLiP latest?d=qj6IDK7rITs latest?i=GBvV9v2aHm8:sy_lNmVREqk:gIN9vFwGBvV9v2aHm8
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments