简体   繁体   English

unix bash shell 脚本相等比较运算符不比较

[英]unix bash shell script equal comparison operator is not comparing

I have the following bash script.我有以下 bash 脚本。 It looks through a directory structure with它通过目录结构查找

YYYY
+ MM
++ DD
+++ HH

I would like to skip the directory in the 17th hour - but the comparison operator我想在第 17 个小时跳过目录 - 但是比较运算符

if [  $ARRVAL == "17" ]

is not working.不管用。 How can i do the above comparison?我怎样才能做上面的比较?

#!/bin/bash
CURRENTDAY=`date +"%d"`
CURRENTHOUR=`date +"%H"`

#date +"%m-%d-%y"
#$now = "$(date + '%Y%d%m%k%M')";
echo TIME IS: "$CURRENTDAY $CURRENTHOUR"
echo blablaba


for D in `find . -type d`
do
    
    t=$D
    a=($(echo "$t" | tr '/' '\n'))
    #echo "${a[4]}"

    #echo ----------- Directory  $D https://stackoverflow.com/questions/10586153/split-string-into-an-array-in-bash
    IFS='/' read -r -a array <<< "$D"
    #echo array has_"${#array[@]}"_elements

    if [ "${#array[@]}" = "5" ]
    then
       echo TESTING $D  comparing  ${array[4]} and $CURRENTHOUR
       ARRVAL="${#array[4]}"
       
       #if [  "${#array[@]}" == "17" ]
       if [  $ARRVAL == "17" ]
       then
            echo current hour       
       fi
    fi
    # if [ "${#array[@]}" = "5"]
    # then
    #     echo $D has 5 elements
    # fi

done完毕

I would like to skip the directory in the 17th hour我想跳过第 17 个小时的目录

find . -mindepth 4 -maxdepth 4 -type d '!' -path './*/*/*/17'

should be enough.应该够了。

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

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