簡體   English   中英

unix bash shell 腳本相等比較運算符不比較

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

我有以下 bash 腳本。 它通過目錄結構查找

YYYY
+ MM
++ DD
+++ HH

我想在第 17 個小時跳過目錄 - 但是比較運算符

if [  $ARRVAL == "17" ]

不管用。 我怎樣才能做上面的比較?

#!/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

完畢

我想跳過第 17 個小時的目錄

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

應該夠了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM