這是正在由sed的編輯的文件:需要驗證我如何SED正在編輯這個文件理解
# cat flyway.conf.j2
flyway.url=jdbc:postgresql://{{ DB_HOST }}:5432/{{ DB_NAME }}?currentSchema=fm_fmp
flyway.user={{ FLYWAY_USER }}
flyway.password={{ FLYWAY_PASSWORD }}
這是代碼片段和評論是我的代碼的理解,是我的理解正確,還有## * /獲取目錄的基本名稱:
# To get the last dir in current working directory, and if you want to do it completely within a bash script without running any external binaries
SCHEMA=${PWD##*/}
#sed -i means inplace, alnum means alphanumeric, 1s (Only search and replace 1st line) searching for string =any_alpha_numeric then _ then {},
# then *$ meaning to the end and replace with value of variable $SCHEMA
sed -i "1s/=[[:alnum:]_{} ]*$/=${SCHEMA}/" flyway.conf.j2
正則表達式期望在'='和行尾之間的任何序列中包含字母數字,'_','{'和'}'。由於':',這不會修改輸入文件的第1行。如果該表達式應用於第2行或第3行,則它將起作用。 – alvits