【发布时间】:2018-01-25 07:05:07
【问题描述】:
这就是我想要做的。我想根据我发现的内容来 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
【问题讨论】:
标签: bash if-statement grep