gpt4 book ai didi

linux - 如何在 unix 中的文本文件中存储多个值

转载 作者:太空宇宙 更新时间:2023-11-04 09:42:03 24 4
gpt4 key购买 nike

我需要在 .ksh 脚本中的单个文本文件中存储多个值并将其作为附件发送到邮件中,下面是我正在处理的示例代码片段

   function 1
{
7za x -p$pass1 $file -aoa
if [ $? -eq 0 ];
then
continue;
fi

7za x -p$pass2 $file -aoa
if [ $? -eq 0 ];
then
continue;
fi

7za x -p$pass4 $file -aoa
if [ $? -eq 0 ];
then
continue;
fi


# Fallthrough.We get here only if all of the above failed.
attachment=`echo $file >/data/mvr/PRESCREEN/IA/test.txt` #<-- Note below
echo "File not extracted see attachement" |mailx -s"Failure" -a attachemnt
acb@xyz.com
done
}

注意:在上面的代码中,我需要将所有未提取的文件名存储在'test.txt'中,然后将其作为附件发送上面的代码仅向我发送未提取的文件的姓氏,而不是列出所有未提取的文件。我该怎么做呢 ?

最佳答案

'>' 是替换运算符。它将在每次迭代时替换目标文件的内容。

'>>' 是串联运算符。它将添加到目标文件的内容。

attachment=`echo $file >>/data/mvr/PRESCREEN/IA/test.txt`

您可能希望在脚本开头添加“/bin/rm/data/mvr/PRESCREEN/IA/test.txt”,以防止其包含之前运行的数据。

关于linux - 如何在 unix 中的文本文件中存储多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20433070/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com