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?
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