shell,将参数与数组进行比较
这是我的密码。在我重新启动电脑之前,它工作得很好。 在重新启动之前,我可能没有保存。我不确定shell,将参数与数组进行比较,shell,text-files,Shell,Text Files,这是我的密码。在我重新启动电脑之前,它工作得很好。 在重新启动之前,我可能没有保存。我不确定 if [[ "${varA[@]}" =~ $comment ]] then echo "This task is already in the Todo list" else x=$(cat $file | wc -l) x=$(($x+1)) echo -e "$x\t$comm
if [[ "${varA[@]}" =~ $comment ]]
then
echo "This task is already in the Todo list"
else
x=$(cat $file | wc -l)
x=$(($x+1))
echo -e "$x\t$comment\t$dueD" >> $file
fi
我想检查$comment
是否在数组varA中,以及它是否存在
echo
it,否则添加它。
请提供帮助。将
$comment
和$file
等变量放在双引号中不会有任何影响。无需$(cat$file | wc-l)
,使用wc-l“$file”
它总是添加到文本文件中。我会尝试这样做,感谢您的建议使用for
来循环数组,并使用=
而不是=~
检查每个元素是否与$comment
完全匹配。用一行愚蠢的语句:if[[$(对于“${varA[@]}”中的e);do-if[[“$e”==“$comment”];then-found=1;break;fi;done;echo$found)]