简体   繁体   中英

unix bash shell script equal comparison operator is not comparing

I have the following bash script. 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

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

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

should be enough.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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