bash script grep using variable fails to find result that actually does exist

后端 未结 2 1646
谎友^
谎友^ 2021-01-29 05:01

I have a bash script that iterates over a list of links, curl\'s down an html page per link, greps for a particular string format (syntax is: CVE-####-####), removes the surroun

2条回答
  •  温柔的废话
    2021-01-29 05:31

    It should look like this:

    # First: Care about quoting your variables!
    
    # Use read to read the file line by line
    while read -r link ; do
        # No grep required. sed can do that.
        curl -s "$link" | sed -n '/CVE-/s/<[^>]*>//gp' | while read -r cve; do
            echo "$cve"
            # grep -F searches for fixed strings instead of patterns
            grep -F "$cve" ./changelog.txt
        done
    done < links.txt
    

提交回复
热议问题