Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

compare two strings in bash if statement

i am trying to make an if statement in a bash script:


    file_exists=$(psql -h $DB_SERVER -U $DB_USER -d $DB_DATABASE -t -c "SELECT source_file FROM $DB_SCHEMA.cj_metadata WHERE source_file LIKE '%$base%';" | grep "$base")
    
    
    echo "FILE EXISTS: $file_exists $base.jsonl"

    # Check if the file exists
    if [[ "$file_exists" == "$base.jsonl" ]]; then
        echo "File $base.jsonl is already saved in DB. Exiting function."
        echo "SELECT source_file FROM cjdb.cj_metadata WHERE source_file = '$base.jsonl';"
        return
    fi

the issue i am having is, that it never goes in the if statement, even if both values are the same:

FILE EXISTS:  LoD2_326625712.jsonl LoD2_326625712.jsonl

what am i doing wrong here? Why is this if statement not working?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

thanks a lot!

>Solution :

FILE EXISTS:  LoD2_326625712.jsonl LoD2_326625712.jsonl

Before the first LoD2_326625712.jsonl, there are two space.

echo "FILE EXISTS: $file_exists $base.jsonl"

Before $file_exists, there is only one space.
So I think there is one extra space before $file_exists

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading