<分区>
我编写了一个使用 if - elif 结构的小脚本。由于某种原因,它只是行不通。 错误代码:
./lab4.sh: line 9: syntax error near unexpected token `elif'
./lab4.sh: line 9: `elif [ $number -eq 2 ] then func2'
我的实际代码:
#!/bin/bash
#ask the user for a number between 1 and 3
#create some functions, write out the function number
echo "Enter a number between 1 and 3: "
read number
#which function should be called?
if [ $number -eq 1 ] then func1
elif [ $number -eq 2 ] then func2
elif [ $number -eq 3 ] then func3 fi
function func1 {
echo "This message was displayed from the first function."
}
function func2 {
echo "This message was displayed from the second function."
}
function func3 {
echo "This message was displayed from the third function."
}