gpt4 book ai didi

linux - elif 的语法错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:58:08 26 4
gpt4 key购买 nike

<分区>

我编写了一个使用 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."
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com