简体   繁体   English

如何删除 bash 脚本中多次出现的变量?

[英]How to remove multiple occurrence of a variable in bash script?

I have the below files in a particular path, and I trying to take the start time and end time from the file name using the cut command in bash script.我在特定路径中有以下文件,我尝试使用 bash 脚本中的 cut 命令从文件名中获取开始时间和结束时间。 Since there are three files in it, it is returning the start date and end dates thrice.由于其中包含三个文件,因此它会三次返回开始日期和结束日期。 Due to which the , if condition followed by it, is not getting satisfied.因此,它后面的if 条件没有得到满足。

The input files are:输入文件是:
indonesia_abc_20210517_20210523.csv indonesia_abc_20210517_20210523.csv
indonesia_hair_20210517_20210523.csv indonesia_hair_20210517_20210523.csv
indonesia_bst_20210517_20210523.csv indonesia_bst_20210517_20210523.csv

PFB the code snippet: PFB 代码片段:

if [ $market  == 'indonesia' ]; then
        file_start_dt=`ls -1 ${parent_dirpath}/temp/${market} | cut -d"_" -f3`
        file_end_dt=`ls -1 ${parent_dirpath}/temp/${market} | cut -d"_" -f4 | cut -d"." -f1`
        echo "file start date, $file_start_dt"
        echo "file_end_date,$file_end_dt"
else 
   echo " not working"
   if [ ${file_start_dt} -eq ${start_date} ] && [ ${file_end_dt} -eq ${end_date} ];
       then
           echo "File uploaded to hdfs path successfully for market : $market"

In the log i observe this - '[' 20210517 20210517 20210517 -eq 20210517 ']'在日志中我观察到这一点 - '[' 20210517 20210517 20210517 -eq 20210517 ']'

Please help me.请帮我。 I'm new to Bash script我是 Bash 脚本的新手

I have the below files in a particular path, and I trying to take the start time and end time from the file name using the cut command in bash script.我在特定路径中有以下文件,我尝试使用 bash 脚本中的 cut 命令从文件名中获取开始时间和结束时间。 Since there are three files in it, it is returning the start date and end dates thrice.由于其中包含三个文件,因此它会三次返回开始日期和结束日期。 Due to which the , if condition followed by it, is not getting satisfied.因此,它后面的if 条件没有得到满足。

The input files are:输入文件是:
indonesia_abc_20210517_20210523.csv indonesia_abc_20210517_20210523.csv
indonesia_hair_20210517_20210523.csv indonesia_hair_20210517_20210523.csv
indonesia_bst_20210517_20210523.csv indonesia_bst_20210517_20210523.csv

PFB the code snippet: PFB 代码片段:

if [ $market  == 'indonesia' ]; then
        file_start_dt=`ls -1 ${parent_dirpath}/temp/${market} | cut -d"_" -f3`
        file_end_dt=`ls -1 ${parent_dirpath}/temp/${market} | cut -d"_" -f4 | cut -d"." -f1`
        echo "file start date, $file_start_dt"
        echo "file_end_date,$file_end_dt"
else 
   echo " not working"
   if [ ${file_start_dt} -eq ${start_date} ] && [ ${file_end_dt} -eq ${end_date} ];
       then
           echo "File uploaded to hdfs path successfully for market : $market"

In the log i observe this - '[' 20210517 20210517 20210517 -eq 20210517 ']'在日志中我观察到这一点 - '[' 20210517 20210517 20210517 -eq 20210517 ']'

Please help me.请帮我。 I'm new to Bash script我是 Bash 脚本的新手

I have the below files in a particular path, and I trying to take the start time and end time from the file name using the cut command in bash script.我在特定路径中有以下文件,我尝试使用 bash 脚本中的 cut 命令从文件名中获取开始时间和结束时间。 Since there are three files in it, it is returning the start date and end dates thrice.由于其中包含三个文件,因此它会三次返回开始日期和结束日期。 Due to which the , if condition followed by it, is not getting satisfied.因此,它后面的if 条件没有得到满足。

The input files are:输入文件是:
indonesia_abc_20210517_20210523.csv indonesia_abc_20210517_20210523.csv
indonesia_hair_20210517_20210523.csv indonesia_hair_20210517_20210523.csv
indonesia_bst_20210517_20210523.csv indonesia_bst_20210517_20210523.csv

PFB the code snippet: PFB 代码片段:

if [ $market  == 'indonesia' ]; then
        file_start_dt=`ls -1 ${parent_dirpath}/temp/${market} | cut -d"_" -f3`
        file_end_dt=`ls -1 ${parent_dirpath}/temp/${market} | cut -d"_" -f4 | cut -d"." -f1`
        echo "file start date, $file_start_dt"
        echo "file_end_date,$file_end_dt"
else 
   echo " not working"
   if [ ${file_start_dt} -eq ${start_date} ] && [ ${file_end_dt} -eq ${end_date} ];
       then
           echo "File uploaded to hdfs path successfully for market : $market"

In the log i observe this - '[' 20210517 20210517 20210517 -eq 20210517 ']'在日志中我观察到这一点 - '[' 20210517 20210517 20210517 -eq 20210517 ']'

Please help me.请帮我。 I'm new to Bash script我是 Bash 脚本的新手

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

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