我試圖創建一個shell腳本來爲Laravel應用程序設置我的Ubuntu服務器。用戶被要求從這裏採取了以下代碼繼續之前確認:用於GNU Bash的Bash shell腳本中的提示用戶配置4.3
How do I prompt a user for confirmation in bash script?
#!/bin/sh
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
echo "\n ${GREEN}Enter the folder name for the Laravel application: ${NC}"
read APP_NAME
read -r -p "Are you sure? [y/N] " response
response=${response,,} # tolower
if [[ $response =~ ^(yes|y)$ ]]
then
echo "Installing dependencies..."
else
exit
fi
我得到這個錯誤:
Bad substitution
上線
response=${response,,} # tolower
你是如何運行腳本?你的代碼很好。什麼操作系統(你說Linux,但這是在一些windoze解釋器下?)測試在'GNU bash,版本4.3.42(1) - 發佈' –
我運行腳本通過調用./script-name後我chmod u + x,在Ubuntu 16.04上運行GNU bash,版本4.3.42(1)-release(x86_64-pc-linux-gnu) –
我會檢查以確保你沒有「回車」或其他一些雜項* Unicode *字符嵌入在腳本中。實際的腳本是確定的。用'hexdump -C yourscriptname'確認。另外,在你的實際腳本中,你在頂部包括'#!/ bin/bash',對嗎? (我不知道Ubuntu使用什麼默認shell) –