如何将文件名传递给 gpg 命令?

How to pass file name into gpg commmand?

我正在从文本文件中读取文件名,并试图将它们传递给 gpg 命令进行加密,但它似乎没有读取变量。

Today.txt

的内容
nm.023000.input
nm.023001.input
nm.033000.input
#!/bin/bash
set -x


cat today.txt | while read line

do

echo $line ;
gpg --trust-model always   --output  $line.gpg --encrypt --recipient user1@gmail.com --yes  $line;


done

我得到的输出是:

+ input=today.txt
+ read line
+ cat today.txt
+ echo

+ gpg --trust-model always --output .gpg --encrypt --recipient user1@gmail.com --yes
+ read line

Out put Expected inside the bash script :- gpg --trust-model always --output nm.023000.input.gpg --encrypt --recipient user1@gmail.com --yes nm.023000.input

目标是创建文件

nm.023000.input.gpg
nm.023001.input.gpg
nm.033000.input.gpg

您可以从输入文件读取,然后使用 while 循环读取每一行,而不是 cat。

#!/bin/bash
input="ab.txt"
while IFS= read -r line
do
echo "${line}";
# gpg --trust-model always   --output  "${line}" --encrypt --recipient user1@gmail.com --yes  "${line}";
done < "${input}"