我正在嘗試在 bash 中創建一個函式:
check_for_file()
{
if [ $1 = '' ]; then
local testing_file = myproject
elif
local testing_file = $1
fi
if [ -d testing_file ]; then
echo "Directory name already exists"
exit
elif
mkdir -p testing_file/{archive,backups,docs/html,docs/txt,assets,database,src/sh,src/c}
fi
return
}
但是當我運行它時,我得到以下輸出:./mkproj.sh:第 10 行:意外令牌fi' ./mkproj.sh: line 10: fi附近的語法錯誤
你知道我做錯了什么嗎?謝謝!
uj5u.com熱心網友回復:
elif期待另一個命令來測驗。格式放在一邊,local testing_file = $1被視為該條件,但隨后關鍵字fi出現在預期then關鍵字之前。
使用else來代替:
if [ $1 = '' ]; then
local testing_file=myproject
else
local testing_file=$1
fi
(同樣請注意,您不能=在作業中在周圍放置空格。
uj5u.com熱心網友回復:
你應該then在elif陳述句之后使用但是你的陳述句也是錯誤的,因為elif需要一個命令來測驗
因此,在您的情況下,只需使用else代替。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/317383.html
上一篇:在Synologynas上重命名檔案名長度超過143個字符的檔案
下一篇:防止時間檢查到使用時間?
