[英]Bash if grep or grep elif grep? So confused
這是我想要做的。 我想根據我發現的內容grep(也許?)一個文件作為關鍵字。
if grep "env=" does not exist OR "env=" exists but is null file.name; then
env=prod
elif grep "env=dev" OR "env=qa" file.name; then
env=dev/qa respectivly
我正在嘗試一些grep命令,但是被卡住了
不確定是否可以得到,仍然需要測試
if ! grep -q -E "^environment=" "${__file}" | grep -q -e "dev|qa|prod"; then
if [ -n "${ENV}" ]; then
echo "environment=${ENV}" >> "${__file}"
else
echo "environment=prod" >> "${__file}"
fi
fi
使用源命令。 將所有局部變量放在名為local_env.sh
文件中。
local_env.sh
樣本內容:
environment=dev
現在您可以創建一個腳本:
source env.sh
# if environment is empty string set it to prod
[ -z "${environment}" ] && environment=prod
echo ${environment}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.