if...else...statement
by CyberIT from LinuxQuestions.org on (#5PZ76)
Im stuck on this if...else...statement.
Code:rm1=$1
rm2=$2
rec1=$2
rec1=$3
input_validation ()
{
if [ rm1=$1 ] && [ rm2=$2 ]; then
if [ $# -ne 2 ]; then
usage
fi
elif [ rm1=$1 ] && [ rm2=$2 ] && [ rec1=$3 ]; then
if [ $# -ne 3 ]; then
usage2
fi
elif [ rm1=$1 ] && [ rec1=$2 ]; then
if [ $# -ne 2 ]; then
usage1
fi
fiCode:if [ "$rec1" == "a" ]; then
...command
...command
elif [ "$rec1" == "b" ]; then
...command
...command
else
...command
...command
fiIt fails on the bold if statement ... I dont know a way around.
First IF statement needs inputs 1 and 2.
Second IF statement needs inputs 1 and 2 and 3.
Third IF statement needs inputs 1 and 3 but not 2.
Please help. Thank you!
Code:rm1=$1
rm2=$2
rec1=$2
rec1=$3
input_validation ()
{
if [ rm1=$1 ] && [ rm2=$2 ]; then
if [ $# -ne 2 ]; then
usage
fi
elif [ rm1=$1 ] && [ rm2=$2 ] && [ rec1=$3 ]; then
if [ $# -ne 3 ]; then
usage2
fi
elif [ rm1=$1 ] && [ rec1=$2 ]; then
if [ $# -ne 2 ]; then
usage1
fi
fiCode:if [ "$rec1" == "a" ]; then
...command
...command
elif [ "$rec1" == "b" ]; then
...command
...command
else
...command
...command
fiIt fails on the bold if statement ... I dont know a way around.
First IF statement needs inputs 1 and 2.
Second IF statement needs inputs 1 and 2 and 3.
Third IF statement needs inputs 1 and 3 but not 2.
Please help. Thank you!