Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I must create a shell script that does the following:

IF "foo" is not in FILE or "boofoogoo" is not in FILE THEN:
  doSomething

  IF "foo" is not in FILE THEN:
     doFooSomething
  END

  IF "boofoogoo" is not in FILE THEN:
     doBooSomething
  END
END

Problem:

If boofoogoo is in FILE but foo is not, then foo is still matched by grep and doBooSomething is not executed.

Here is the actual code which is running:

PYPY_HOST="myprivate-pypi.com"
PYPI_URL="https://$PYPY_HOST:8000/simple"

config_file=$(get_config_file)
url_exist=$(find $config_file -type f -exec grep -l "$PYPI_URL" {} ;)
host_exist=$(find $config_file -type f -exec grep -l "$PYPY_HOST" {} ;)

if [ -z "host_exist" ] || [ -z "$url_exist" ]; then

    echo "" >> $config_file
    echo "$GLOBAL_TAG" >> $config_file

    if [ ! -z $url_exist ]; then
        echo "Extra url found"
    else            
        echo "Adding extra url"
        echo "$EXTRA_URL" >> $config_file
    fi

    if [ ! -z $host_exist ]; then
        echo "Trusted host found"
    else
        echo "Adding trusted host"
        echo "$TRUSTED_HOST" >> $config_file
    fi
else
    echo "Do nothing"
fi

Expected final output is:


[global] 
extra-index-url = https://myprivate-pypi.com:8000/simple
trusted-host = myprivate-pypi.com

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.3k views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...