2017-08-17 9 views
0

ここに私がやろうとしていることがあります。私はgreah(多分?)私が何を見つけるかに基づいてキーワードのファイルをしたいです。bashのgrepまたはgrep elif 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 

答えて

0

sourceコマンドを使用してテストする必要があるなればわからないで立ち往生ました。すべてのローカル変数をlocal_env.shという名前のファイルに入れます。 local_env.sh

サンプルコンテンツ:

source env.sh 
# if environment is empty string set it to prod 
[ -z "${environment}" ] && environment=prod 
echo ${environment} 

environment=dev 

は今、あなたはスクリプトを作成することができます