Article 4WRJ8 [SOLVED] my if elif else statement in bash is not giving me the desired result

[SOLVED] my if elif else statement in bash is not giving me the desired result

by
dan-german
from LinuxQuestions.org on (#4WRJ8)
my question is:

1) i wrote an if,elif,else statement which ran successfully and gave me the desired output,but when i placed that same statement in a bash function,it did not run successfully. i can not figure out where am getting wrong.please can someone help me go through my bash script,thank you.

1) This if,elif,else statement ran succesfully

#!/bin/bash

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

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

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

echo "have got your back"
fi

2) When i put the above statement in a bash function,it did not give me the desired results.

#!/bin/bash

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

AddVariable () {

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

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

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

printname "$Variable1"
deletename "$Variable2"

fi

}

deletename(){

for file in $Variable2/*;do

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

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

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

#printname "$Variable1"
#deletename "$Variable2"
AddVariable

please i am new to bash scripting thank youlatest?d=yIl2AUoC8zA latest?i=2VeVHTAQ7fk:maYw4oiddp4:F7zBnMy latest?i=2VeVHTAQ7fk:maYw4oiddp4:V_sGLiP latest?d=qj6IDK7rITs latest?i=2VeVHTAQ7fk:maYw4oiddp4:gIN9vFw2VeVHTAQ7fk
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