[英]Error: For loop is not working in shell script
我有一個文件中的文件列表,我試圖迭代該文件,但 for 循環不起作用。 你能幫我么?
例子:
list_file.txt
EMAIL_MSG
CALL
TERR
CASE
Shell 腳本:
ls -1tr ${incremnt_ec2_path}|awk -F"/" '{print $NF}' > list_file.txt
for f in `cat list_file.txt`;
do
Foldername=`echo "$f"`
echo $Foldername
aws s3 cp ${bucket}${Daily_Src_Location}/$Foldername ${archivebucket}/SrcFiles/AMPIL/AMPIL_SRC_${logdate1}/$Foldername/ --recursive --sse >> ${log_out_file}'Lnd_load_valdtn'_${logdate1}.log 2>&1
printf "aws s3 cp ${bucket}${Daily_Src_Location}/$Foldername ${archivebucket}/SrcFiles/AMPIL/AMPIL_SRC_${logdate1}/$Foldername/ --recursive --sse" >> ${log_out_file}'Lnd_load_valdtn'_${logdate1}.log 2>&1
done
它僅顯示EMAIL_MSG
並退出循環。
這行得通嗎:?
while read Foldername
do
echo $Foldername
aws s3 cp ${bucket}${Daily_Src_Location}/$Foldername ${archivebucket}/SrcFiles/AMPIL/AMPIL_SRC_${logdate1}/$Foldername/ --recursive --sse >> ${log_out_file}'Lnd_load_valdtn'_${logdate1}.log 2>&1
printf "aws s3 cp ${bucket}${Daily_Src_Location}/$Foldername ${archivebucket}/SrcFiles/AMPIL/AMPIL_SRC_${logdate1}/$Foldername/ --recursive --sse" >> ${log_out_file}'Lnd_load_valdtn'_${logdate1}.log 2>&1
done < cat list_file.txt
我假設您已經正確設置了其他變量。例如: $bucket
, $Daily_Src_Location
如果這不起作用,請將您收到的確切 output 添加為 + 錯誤
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.