主要有三個檔案test.cnf test.sh test.txt
執行test.sh去讀取test.cnf的設定來修改test.txt的內容,執行過程中讀取設定成功但sed執行的時候沒找到。
sed這裡只是調試沒去修改test.txt,只是顯示test.txt的結果
[root@localhost /tmp]# head -100 test*
==> test.cnf <==
yy=123
ppp=456
==> test.sh <==
function myconf(){
source test.cnf
awk -F'=' '{print }' test.cnf|while read myline;do sed s/{{$myline}}/${$myline}/g test.txt;done
}
myconf
==> test.txt <==
uuu={{yy}}
ooo={{ppp}}
調試的時候就顯示執行錯誤;
[root@localhost /tmp]# bash -x test.sh
+ myconf
+ source test.cnf
++ yy=123
++ ppp=456
+ read myline
+ awk -F= '{print }' test.cnf
test.sh: line 4: s/{{$myline}}/${$myline}/g: bad substitution
其它方法: