我正在尝试在 bash 脚本中创建 if 语句:
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
我遇到的问题是,它永远不会出现在 if 语句中,即使两个值相同:
FILE EXISTS: LoD2_326625712.jsonl LoD2_326625712.jsonl
我在这里做错了什么?为什么这个 if 语句不起作用?
非常感谢!
FILE EXISTS: LoD2_326625712.jsonl LoD2_326625712.jsonl
第一个LoD2_326625712.jsonl之前有两个空格。
echo "FILE EXISTS: $file_exists $base.jsonl"
$file_exists
之前只有一个空格。
所以我认为 $file_exists 之前多了一个空格