简体   繁体   English

错误:For 循环在 shell 脚本中不起作用

[英]Error: For loop is not working in shell script

I have list of files in a file which I am trying to iterate over the file but for loop is not working.我有一个文件中的文件列表,我试图迭代该文件,但 for 循环不起作用。 Can you please help me?你能帮我么?

Example:例子:

list_file.txt

EMAIL_MSG
CALL
TERR
CASE

Shell Script: 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

It is showing only EMAIL_MSG only and coming out of loop.它仅显示EMAIL_MSG并退出循环。

Does this work: ?这行得通吗:?

    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

I assume you already have the other variables all set properly.. like: $bucket , $Daily_Src_Location我假设您已经正确设置了其他变量。例如: $bucket$Daily_Src_Location

If this does not work, please add the exact output you are receiving as + errors如果这不起作用,请将您收到的确切 output 添加为 + 错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM