我想做一个基本的
if [[ "$string" =~ "$substring" ]]; then
echo "True"
else echo "False"
fi
然而,我正在寻找的子字符串看起来像“THING ='$ VAR'”而且它不会飞。是的,$ VAR是我代码中的一个变量。帮助
以下是我正在查看的内容示例($ string是从文件中提取的):
# $string = "THIS = stuff / more random letters taking up space MORE STUFF = '42 ' here's some numbers asdgh asdgjhd a;lkdjg asdlkja dddd 'a::' THING = 'R ' more specs = THIS and THAT END"
for VAR in V R I B WA NA HA1 HA4 HA5; do
substring="SUBSET = '$VAR '"
if [[ "$string" =~ "$substring" ]]; then
echo "True"
else echo "False"
fi
done
如果这不是更有启发性,我道歉。也许在如此多的引用中使用变量实际上并没有提出变量,但是当我打印出$ substring时,它会说THING ='V'。