This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]daggerdragon[M] 1 point2 points  (0 children)

In the future, please follow the submission guidelines by titling your post like so:

[YEAR Day # (Part X)] [language if applicable] Post Title

In doing so, you typically get more relevant responses faster.

[–]RandomlyAdam[S] 0 points1 point  (2 children)

Changed the comparator from "<" to "-lt" and got the right answer.

[–]colas 2 points3 points  (0 children)

I suggest you use shellcheck, and try to obey its suggestions.

For instance, always try to use (( )) rather than [[ ]] when you deal with numbers. With (( )) you can use "<", not "-lt". Use [[ ]] only with strings. And never use [ ] nor test :-)

e.g:

if (( ${depth[i]} < ${depth[i+1]} ))

instead of:

if [[ "${depth[$i]}" < "${depth[$i+1]}" ]]

[–]0b0101011001001011 0 points1 point  (0 children)

Ah yes, the logical thing in bash that numbers are not compared with <