特殊コンテンツと1行ずつ[重複]

特殊コンテンツと1行ずつ[重複]

同志!ファイルがあります:

# cat file
'\\.\Aktiv Co. Rutoken S 00 00\USER1@R69-20180109'
'\\.\Aktiv Co. Rutoken S 00 01\USER2@R69-20180109'

1行ずつ実行する必要があります。

for LINE in `cat file` 
do
/opt/cprocsp/bin/amd64/certmgr -inst -cont $LINE
done

しかし!ファイルに '\. 「set -x」を使用してスクリプトを起動すると、次のようになります。

+ for LINE in '`cat file`'
+ /opt/cprocsp/bin/amd64/certmgr -inst -cont ''\''\\.\Aktiv'
Error
+ for LINE in '`cat file`'
+ /opt/cprocsp/bin/amd64/certmgr -inst -cont Co.
Error
+ for LINE in '`cat file`'
+ /opt/cprocsp/bin/amd64/certmgr -inst -cont Rutoken
Error
+ for LINE in '`cat file`'
+ /opt/cprocsp/bin/amd64/certmgr -inst -cont S
Error
+ for LINE in '`cat file`'
+ /opt/cprocsp/bin/amd64/certmgr -inst -cont 00
Error
+ for LINE in '`cat /home/user/Aktiv`'
+ /opt/cprocsp/bin/amd64/certmgr -inst -cont '00\USER1@R69-20180109'\'''
+ for LINE in '`cat file`'
+ /opt/cprocsp/bin/amd64/certmgr -inst -cont ''\''\\.\Aktiv'
Error
+ for LINE in '`cat file`'
+ /opt/cprocsp/bin/amd64/certmgr -inst -cont Co.
Error
+ for LINE in '`cat file`'
+ /opt/cprocsp/bin/amd64/certmgr -inst -cont Rutoken
Error
+ for LINE in '`cat file`'
+ /opt/cprocsp/bin/amd64/certmgr -inst -cont S
Error
+ for LINE in '`cat file`'
+ /opt/cprocsp/bin/amd64/certmgr -inst -cont 00
Error
+ for LINE in '`cat /home/user/Aktiv`'
+ /opt/cprocsp/bin/amd64/certmgr -inst -cont '01\USER2@R69-20180109'\'''

理想的には、次のようにする必要があります。

/opt/cprocsp/bin/amd64/certmgr -inst -cont '\\.\Aktiv Co. Rutoken S 00 00\USER1@R69-20180109'
/opt/cprocsp/bin/amd64/certmgr -inst -cont '\\.\Aktiv Co. Rutoken S 00 01\USER2@R69-20180109'

これはすべて特別なコンテンツ(ファイル)から出てくると思います。どんなアイデアがありますか?

ベストアンサー1

cat fileはい、出力を繰り返すと性格

1つの解決策:

PATH=/opt/cprocsp/bin/amd64:$PATH

while IFS= read -r line; do
    certmgr -inst -cont "$line"
done <file

これにより、行を1行ずつ読み、バックスラッシュと単語の間のスペースを正しく読み込みます。引用符を参照してください$line。望むより」「IFS=read-r-line」を理解する」。

もともと私は使用したバージョンを含めましたが、場合によってはこれがデータのバックスラッシュを維持せずに一重引用xargs符を削除したことに気づきました。file

おすすめ記事