我要问这个问题:“你想用什么格式?”,那么,这取决于答案是否xml
或json
,打印适当的输出。但是,如果它不是xml
或json
,则代码结束。的if else语句
代码:
#!/bin/bash
read -r -e -p "What format do you want to use? json/xml?: " format
if [[ "${format,,}" == "json" ]]; then
curl=$curl"\"\Content-Type: application/json\"\
else [[ "${format,,}" == "xml" ]]; then
curl=$curl"\"\Content-Type: application/xml\"\
elif [[ "${format,,}" == "no" ]]; then
echo "Goodbye, you must specify a format to use Rest"
else
echo "Unknown"
exit 0
fi
echo $curl
我收到此错误,当我尝试运行它:
[[email protected] groups]# ./test3
What format do you want to use? json/xml?: xml
./test3: line 8: syntax error near unexpected token `then'
./test3: line 8: `elif [[ "${format,,}" == "no" ]]; then'
这是一种很好的方式来表示我正在编写的代码,它一定会派上用场。谢谢 – Aaron
@Aaron yvw - 享受:) – jm666