I was writing a script using bash. It consist in a loop to change the background image of my desktop. So easy!! My Brother was helping me. We did it, and we used it for a long time in our laptops and we got fun adding new pictures to the images gallery. We finished the script and enjoyed the script but a new problems was in front of us: We were loading the images as a sequence and the sequence was the same always, so, the images order was the same every time. We was thinking about randomize the images, but I don’t have idea about bash programming and my brother either.
This days a friend was in my city because of his job and he visited me. I showed him the script, I explained him and I told him about our idea of randomize images. He was thinking a solution and he was involved in the script development. We found a shell web page with some examples, commands and their explain. We used it for our script.
Each time we change the script we test, but each time we saw the same mistake. We stored the images name into an array and we got a random number that is the array position and we showed this image by 120 seconds and next we deleted the displayed image, and we repeated this process until the array is empty. When the array is empty we load the image names again. This was our idea, but it not works!! sometimes, our script showed us a green image, that is displayed when the image is not found. Well we fixed the script and we accepted the character ‘ ‘ in the names… But it didn’t works. I tested severely, i followed the algorithm and I discovered the mistake: The page that we read said about a command that ” returns the size of an array” BUT this command returned the number of element into an array not their size!!!, so we delete the image name but the array was the same size BUT the number of elements into our array had one less, so the array position that we deleted was empty and the random command sometimes returned us this empty position, as a consequence, the image named ” was not found!!
This could be obvious, but my friend, my brother and me have no idea about bash. Each programming language is different and in the “Practical Examples” page “we found what we need” but it was not true!! At the end of the day we had a conclusion: RTFM, there is not a different explain for us.