Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
shell,将参数与数组进行比较_Shell_Text Files - Fatal编程技术网

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)]