我正在嘗試撰寫簡單的 shell 腳本來決議屬性檔案并根據這些值計算另一個字串。
開發屬性
com.global.jdbcUrl=${local_jdbcUrl}
環境變數
export local_jdbcUrl="jdbc:mysql://localhost:3306/db_0?autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true"
.bash 檔案:
#!/bin/bash
file="./dev.properties"
function prop {
grep "${1}" ${file} | cut -d'=' -f2
}
text="global"
keys="jdbcUrl"
IFS=','
read -a strarr <<< "$text"
read -a keysarr <<< "$keys"
echo "There are ${#strarr[*]} words in the text.\n"
echo "There are ${#keysarr[*]} words in the text. \n\n"
for val in "${strarr[@]}";
do
for refs in "${keysarr[@]}";
do
tmp="$val.$refs"
printf "name : $tmp\n\n"
valu="$(prop $tmp)"
printf "value : $valu \n"
printenv local_jdbcUrl
done
done
此腳本的輸出:
There are 1 words in the text.\n
There are 1 words in the text. \n\n
name : global.jdbcUrl
value : ${local_jdbcUrl}
jdbc:mysql://localhost:3306/db_0?autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true
我正在使用 shell 腳本運行遷移,因此要形成遷移字串命令,我需要在字串中包含實際的環境變數值。環境變數替換沒有發生。不知道這里有什么問題。有人可以幫助我是 bash 腳本的新手。我檢查了 shell 腳本中的環境值,它作業正常,只是在 bash 腳本中我收到了這個錯誤。
uj5u.com熱心網友回復:
也許envsubst
$ cat file
${HOME} is where the heart is
$ cat file | envsubst
/home/glennj is where the heart is
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/466164.html
