Edit: SOLVED. Thank you all for your incredible insights! All of you helped me improve my code and knowledge! Special thanks to @Quibblekrust@thelemmy.club who just NAILED it. :)

I’m playing around with Bash just to learn.

LIST=$(ls); for i in $LIST; do echo "I found one!"; done

The variable “i” could literally be anything, as long as it doesn’t have a special meaning for Bash, in which case I’d have to escape it, right? Anyway, my real question is: how does do (or rather the whole for-expression) know that “i” here means “for every line/item that ls outputs”? The above one liner works great and writes “I found one!” the number of times corresponding to the number of lines or items that ls outputs. But I would like to understand why it worked…

I’m a complete beginner at both Bash and C, but I understand some basic concepts.

  • emotional_soup_88@programming.devOP
    link
    fedilink
    English
    arrow-up
    6
    ·
    4 days ago

    I was a teacher for some years and I absolutely understand your style of explanation. I don’t find it condescending at all! Thank you so much for the in depth guidance! Some of it I already knew, some of it I didn’t. Anyhow, a new perspective is always appreciated! :) God, Bash (GNU/Linux in general) is so much fun!

    • harsh3466@lemmy.ml
      link
      fedilink
      arrow-up
      4
      ·
      4 days ago

      I was also a teach for a number of years! Hello fellow teacher. :)

      I agree. Bash, and GNU/Linux in general is amazing. My recent foray has been into Python, and I’m having an utter blast writing code and learning.