エラーを投稿せずに bash スクリプト内のファイル名をデトックスするにはどうすればよいですか?

エラーを投稿せずに bash スクリプト内のファイル名をデトックスするにはどうすればよいですか?

OS: Kubuntu 22.04.4 LTS x86_64
デトックス 1.4.5

上記を表示するには:

neofetch --stdout |grep 'OS:'
detox -V

以下は s1 で始まる有害なファイル名です:

s1 Ä Ö Ü - ä ö ü Science & < > " 1 \ 2 ⁄ 3 | ? * (&&9&&&) ::::z.pdf

script1ターミナルにコピーして貼り付けました。 script1出力は上記の有害なファイル名で機能します"$FILE1":

filename_before_detox='s1 Ä Ö Ü - ä ö ü Science & < > " 1 \ 2 ⁄ 3 | ? * (&&9&&&) ::::z.pdf'
filename_after__detox= s1_A_A-Aoe-A_A_pp_A_Science_and_1_2_a_3-and_and_9_and_and_and-z.pdf

script1動作し、結果として、デトックスされたファイル名が提供されます。スペースや特殊文字は使用できません。以下の変換された、名前が変更されたファイル名を参照してください。

s1_A_A-Aoe-A_A_pp_A_Science_and_1_2_a_3-and_and_9_and_and_and-z.pdf

script1:

clear 
DIR1=$HOME/Downloads    # DIR1=/home/x/Downloads 
cd $DIR1
ls -alF s1*    # List all filenames starting with s1
FILE1='s1 Ä Ö Ü - ä ö ü Science & < > " 1 \ 2 ⁄ 3 | ? * (&&9&&&) ::::z.pdf'
  detox -s iso8859_1    "$FILE1" 
# detox -s iso8859_1 -v "$FILE1" # v=verbose 
ls -alF s1*    # List all filenames starting with s1

script2動かない:

エラー = そのようなファイルまたはディレクトリはありません

script2自動的に新しいファイルを検出しDIR1 = ~/Downloadsscript2アクセス時に最終的に clamscan を実行してテスト中にウイルスをDIR1検出し、ダウンロードをシミュレートするために手動で貼り付けます。
FILE1DIR1

各種見積結果:

detox -s iso8859_1  "$FILE1"    # No such file or directory
detox -s iso8859_1 '"$FILE1"'   # No such file or directory
detox -s iso8859_1 ""$FILE1""   # posting errors then ok result 

script2

clear 
DIR1=$HOME/Downloads    # DIR1=/home/x/Downloads 
inotifywait -q -m -e close_write,moved_to --format '%w%f' "$DIR1" |while read FILE1
do 
ls -alF s1*             # List all filenames starting with s1
detox -s iso8859_1 ""$FILE1"" 
ls -alF s1*             # List all filenames starting with s1
done

script2エラーがありますが、結果は正常です:

s1_A_A-Aoe-A_A_pp_A_Science_and_1_2_a_3-and_and_9_and_and_and-z.pdf

しかし、多くの誤りがあります:

rw-rw-r-- 1 x x 1153263 Mar 13 11:36 's1 Ä Ö Ü - ä ö ü Science & < > " 1 \ 2 ⁄ 3 | ? * (&&9&&&) ::::z.pdf'
/home/x/Downloads/s1: No such file or directory
Ä: No such file or directory
Ö: No such file or directory
Ü: No such file or directory
-: No such file or directory
ä: No such file or directory
ö: No such file or directory
ü: No such file or directory
Science: No such file or directory
&: No such file or directory
<: No such file or directory
>: No such file or directory
": No such file or directory
2: No such file or directory
⁄: No such file or directory
3: No such file or directory
|: No such file or directory
(&&9&&&): No such file or directory
::::z.pdf: No such file or directory
-rw-rw-r-- 1 x x 1153263 Mar 13 11:36 s1_A_A-Aoe-A_A_pp_A_Science_and_1_2_a_3-and_and_9_and_and_and-z.pdf
-rw-rw-r-- 1 x x  1153263 Mar 13 11:36 s1_A_A-Aoe-A_A_pp_A_Science_and_1_2_a_3-and_and_9_and_and_and-z.pdf
-rw-rw-r-- 1 x x 1153263 Mar 13 11:36 s1_A_A-Aoe-A_A_pp_A_Science_and_1_2_a_3-and_and_9_and_and_and-z.pdf

どういうdetox意味?

  • detox= ファイル名を整理する
  • このユーティリティは、ファイル を操作しやすくするdetoxためにファイル名を変更します。
  • スペースやその他の煩わしさを取り除きます。
  • また、8 ビット ASCII でエンコードされた Latin-1 (ISO 8859-1) 文字、UTF-8 でエンコードされた Unicode 文字、および CGI エスケープ文字も変換またはクリーンアップします。

inotifywait= inotifyを使用してファイルの変更を待機します

  • inotifywaitLinux のインターフェースを使用してファイルの変更を効率的に待機しますinotify(7)
  • シェル スクリプトからのファイルの変更を待機するのに適しています。
  • イベントが発生すると終了するか、または継続的に実行して、発生するイベントを出力することができます。

エラーを投稿せずに bash スクリプト内のファイル名をデトックスするにはどうすればよいですか?

関連情報