cut および grep コマンドが動かなくなる可能性があると思います。[ -n "$string" ]
コマンドを使用して空でないかどうかを確認し、パラメータが空でないことを確認する必要$string
があります。あなたの場合、それが空の場合、後でそれを使用するコマンドにファイルを追加しません。つまり、コマンドはおそらくコマンドラインからの入力を待機します(例:$string
が空の場合grep regex $string
、 grep はから入力ファイルを受信$string
せず、代わりにコマンド ラインからの入力を待ちます)。これは、どこで問題が発生する可能性があるかを示す「複雑な」バージョンです。
while [[ $startTime -le $endTime ]]
do
thisfile=$(find * -type f)
if [ -n "$thisfile" ]; then
thisfile=$(grep -l $startDate $thisfile)
if [ -n "$thisfile" ]; then
thisfile=$(grep -l $startTime $thisfile)
if [ -n "$thisfile" ]; then
thisfile=`cut -d$ -f2 $thisfile`
if [ -n "$thisfile" ]; then
forDestination=`cut -d ~ -f4 $thisfile`
echo $fordestination
fi
fi
fi
fi
startTime=$(( $startTime + 1 ))
done
そして、これがより単純なバージョンです:
while [[ $startTime -le $endTime ]]
do
thisfile=$(grep -Rl $startDate *)
[ -n "$thisfile" ] && thisfile=$(grep -l $startTime $thisfile)
[ -n "$thisfile" ] && thisfile=`cut -d$ -f2 $thisfile`
[ -n "$thisfile" ] && cut -d ~ -f4 $thisfile
startTime=$(( $startTime + 1 ))
done
"-R" は grep にファイルを再帰的に検索するように指示し、&&
は bash に前のコマンドが成功した場合にのみ後続のコマンドを実行するように指示し、前のコマンド&&
はテスト コマンド ( if
s で使用) です。
これが役立つことを願っています=)