1
テキストファイルからファイル名を読み込み、ディレクトリに存在するかどうかを確認する簡単なbashスクリプトを作成しています。これは正常に動作しますが、すべてのファイルが解析された後、無限ループに陥っています。ファイルを読み取っている間にBashスクリプトの無限ループ
#!/bin/bash
if [ "$1" = "" ]; then
echo "No input file to parse given. Give me an input file and make sure the corresponding .gz files are in the folder."
else
file=$1
echo "Loaded $file."
while read -r line
currentfile="$line.gz"
do
if [ -f $currentfile ]; then
echo "The file '$currentfile' exists."
else
echo "The file '$currentfile' does not exist."
fi
done < "$file"
fi
そして、すべてのファイルが一覧表示された後、これはループ出力です:
The file '.gz' does not exist.
The file '.gz' does not exist.
The file '.gz' does not exist.
The file '.gz' does not exist.
The file '.gz' does not exist.
The file '.gz' does not exist.
etc.
私は解決策は非常に単純である必要があります知っているが、それは朝のほとんどのために、私を盗聴されています!どんな助けにも感謝!
多くの義務づけられた親切なサー! – ScubaChris
@ScubaChris:ちょうどupvote /答えを受け入れる:) – choroba