2017-02-17 8 views
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. 

私は解決策は非常に単純である必要があります知っているが、それは朝のほとんどのために、私を盗聴されています!どんな助けにも感謝!

答えて

1

割り当て

currentfile="$line.gz" 

readdoの間でも属していない、それをしませんか?それは条件を常に真にします。

doの後に移動します。

+0

多くの義務づけられた親切なサー! – ScubaChris

+0

@ScubaChris:ちょうどupvote /答えを受け入れる:) – choroba

関連する問題