读取文件

时间:2017-02-17 10:30:52

标签: bash infinite-loop readfile

我正在编写一个简单的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 个答案:

答案 0 :(得分:1)

作业

public interface StockDetlRepository extends JpaRepository<StockDetl, Long>, QueryDslPredicateExecutor<StockDetl> {

    @Query("SELECT sd from StockDetl sd, Stock s, StockPriceMast spm WHERE s.id = sd.stockId AND s.madtId = spm.id AND s.stockSymbol = ?1 AND spm.trandDate BETWEEN ?2 AND ?3")
    List<StockDetl> findPricesByStockSymbolAndDate(String stockSymbol, Timestamp fromTranDate, Timestamp toTranDate);

}

不属于 currentfile="$line.gz" read,是吗?它使条件始终如一。

do之后移动它。