Reputation: 464
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
Upvotes: 1
Views: 316
Reputation: 141145
I would like to skip the directory in the 17th hour
find . -mindepth 4 -maxdepth 4 -type d '!' -path './*/*/*/17'
should be enough.
Upvotes: 2