我要問這個問題:「你想用什麼格式?」,那麼,這取決於答案是否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