#!/bin/bash
echo "What is the vendor? (DELL or CISCO)" #this is an example for reference
read VENDOR #this is an example for reference
if [ "$VENDOR" = "DELL" ]; then
echo "Step 1: Configuring DELL switch..."
# DELL-specific commands go here
elif [ "$VENDOR" = "CISCO" ]; then
echo "Step 1: Configuring CISCO switch..."
# CISCO-specific commands go here
else
echo "Invalid vendor entered. Exiting script."
exit 1
fi
if [ "$VENDOR" = "DELL" ]; then
echo "Step 2: Configuring DELL router..."
# DELL-specific commands go here
elif [ "$VENDOR" = "CISCO" ]; then
echo "Step 2: Configuring CISCO router..."
# CISCO-specific commands go here
fi
if [ "$VENDOR" = "DELL" ]; then
echo "Step 3: Configuring DELL firewall..."
# DELL-specific commands go here
elif [ "$VENDOR" = "CISCO" ]; then
echo "Step 3: Configuring CISCO firewall..."
# CISCO-specific commands go here
fi
if [ "$VENDOR" = "DELL" ]; then
echo "Step 4: Configuring DELL VPN..."
# DELL-specific commands go here
elif [ "$VENDOR" = "CISCO" ]; then
echo "Step 4: Configuring CISCO VPN..."
# CISCO-specific commands go here
fi
if [ "$VENDOR" = "DELL" ]; then
echo "Step 5: Configuring DELL WAN..."
# DELL-specific commands go here
elif [ "$VENDOR" = "CISCO" ]; then
echo "Step 5: Configuring CISCO WAN..."
# CISCO-specific commands go here
fi
echo "Script completed successfully."
请不要关注剧本的内容,而要关注剧本的类型。
我需要一种高效的方法(更少的代码行)来运行5个以上的步骤,其中每个步骤基于$Var1的值(在本例中为$VENDOR)执行相同操作的不同变体
1条答案
按热度按时间llew8vvj1#
简化版:
Don't use UPPER case variables