我不明白为什么比较字符串在这里不起作用:
while IFS=, read -r ELMS_SIZE ELMS_NAME ELMS_ENV ELMS_DB
do
if [ "${ELMS_DB}" = "NOMATCH" ]; then
echo "done"
fi
done < <(tac ${CSM_DATA_DIR}/test.csv)
exit
ELMS_DB
字符串值为NOMATCH
,test.csv 的输出示例
12 am_pltconfig9 unknown NOMATCH
12 am_pltconfig8 unknown NOMATCH
12 am_pltconfig7 unknown NOMATCH
12 am_pltconfig6 unknown NOMATCH
答案1
根据您的示例test.csv
,您的文件实际上不是逗号分隔的,而是空格分隔的。尝试将 while read 循环更改为:
while read -r ELMS_SIZE ELMS_NAME ELMS_ENV ELMS_DB
do
if [ "$ELMS_DB" = "NOMATCH" ]; then
echo "done"
fi
done < <(tac "${CSM_DATA_DIR}/test.csv")
exit