Skip Navigation

InitialsDiceBearhttps://github.com/dicebear/dicebearhttps://creativecommons.org/publicdomain/zero/1.0/„Initials” (https://github.com/dicebear/dicebear) by „DiceBear”, licensed under „CC0 1.0” (https://creativecommons.org/publicdomain/zero/1.0/)H
Posts
20
Comments
612
Joined
2 yr. ago

  • It would not, as @Quibblekrust@thelemmy.club explained in their comment (which I neglected to include in my explanation), Bash uses a special variable called IFS when executing for loops like this. IFS stands for Input Field Separators, and is a list of one of each type of whitespace (tab, space, and newline), and uses these as separators automatically.

    So instead of taking that whole ls output as one string of text, the for loop automatically separates it into an iterable list of strings using the newline separator.

  • 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.

  • You've got a few things going on to be broken down here.

    And forgive me if anything I say here seems condescending, it's not meant to be, I just like to be very explanatory with things like this and to assume the reader may not know anything about anything. (Not as an insult, but simply as a gap in knowledge).

    Also, while I'm proficient at Bash, I'm no expert.

    LIST=$(ls): Here you've stored the output of the ls command to the variable LIST, which gives you a list of items in the given directory, in this case, whichever directory the command is run from. It's also a good idea to quote the variable assignment like this: "$(ls)".

    for i in $LIST;: This is the first part of the for loop statement, which is an iterator, meaning, it will loop or iterate over every item in the given variable/parameter/group of iterable items.

    The i here, as you said could be anything. You could say for file in $LIST; or for item in $LIST;. It doesn't matter, because it's just a variable name that you are using in the first part of the for statement.

    So what bash will do with this is loop over the list, and take each item in the list, and assign it to the variable i, which will allow you do act upon that single item by calling the variable i in some other commands.

    do echo "I found one!";: This is the next part of the for loop, which is the instruction set to be executed inside the for loop. Here is where you can act upon the items in your list that have been assigned to the variable i.

    In your case, you're just printing a statement to stdout (standard out), that says, "I found one!"

    It's like saying, for each item in this list, print "I found one!"

    So if there are 20 items in the list, it will print that statement 20 times.

    However, maybe you want to print the item itself as part of a statement. So instead of "I found one!", you could do something like:

    do echo "I found $i!"

    Which then would print "I found some-filename-or-directory-here!" for each item in your list.

    done: Finally, the done statement tells bash that this is the end of the for loop. So any commands after the done statement will only run once the for loop has iterated over all items in the list and executed the commands inside the for loop for each item on the list.

    A couple of notes:

    The ; is used as a command separator or terminator. So bash knows to first run LIST=$(ls) before it attempts to run whatever the next command might be.

    In bash, it's good practice to always quote your variables like so: for i in "$LIST";. This is to avoid errors for characters that might need escaping like whitespace, backslashes, and other special characters.

    With that in mind, if you're running a command like echo "I found $i!", you don't need to quote the variable again, because it's already inside a quote set.

    Further, it's not absolutely necessary, but it can also be a good idea to also enclose all of your variables in {}, so whenever you use a variable, you'd do something like: "${LIST}"

    This not only more clearly identifies variables in your bash scripts/commands, but is necessary when using bash's parameter expansion, which is pretty great.

  • Can you share the dongle you got? I tried a couple of bt dongles and they SUCKED.

  • Exactly!!!

  • Yeah. The peace prize(s) are a joke

  • Don't people know the key to peace is bombing and killing the shit out of everyone you don't agree with/like? /s

  • The key here is (emphasis added):

    I'll work a 9-5 if it means I can afford... ...fair quality food

    I know you mention your privilege, and I'm glad you're in the position you're in where your job gives you the means and you live where you have access to a variety of good quality food. (I'm not glad the job makes you miserable.)

    For so many, that's just not the case. We can't afford it, or if we can, we're not just working a 9-5, we're working two or more jobs, 10 or more hours a day, and shitty hours, more than five days a week, living in food deserts where food quality is terrible, and on and on.

    Now, I agree with you. I'd be perfectly happy working my main job (I work two), if it meant I could afford to live my life without the constant stress of trying to afford to just exist.

    Compare that to hunter gatherer lifestyle, where they worked to hunt/gather/shelter/etc themselves for 20ish hours a week and had significantly more leisure time and less stress.

    Given the choice between the two, I'd live the hunter gatherer lifestyle rather than working 50+ hours a week as a wage slave to barely keep my head above water. And I know that's not all daisies and rainbows either, but fuck capitalism and this construct we're currently living in.

  • Programming @programming.dev

    Looking for feedback on a python class definition

  • It is! I'm gonna have to give it a listen soon. It's been a long while since I listened to it.

  • Thank you for the pointers! Didn't take it as a put down at all. I appreciate the feedback, and your bash script.

    I didn't realize that gluetun had added this functionality, so I'll likely implement that as the more efficient way to keep the port updated.

  • Thank you! I'm gonna take a look at flaresolvarr too.

  • Love this song

  •  
        
    find /path/to/starting/dir -type f -regextype egrep -regex 'some[[:space:]]*regex[[:space:]]*(goes|here)' -exec mv {} /path/to/new/directory/ \;
    
      

    I routinely have to find a bunch of files that match a particular pattern and then do something with those files, and as a result, find with -exec is one of my top commands.

    If you're someone who doesn't know wtf that above command does, here's a breakdown piece by piece:

    • find - cli tool to find files based on lots of different parameters
    • /path/to/starting/dir - the directory at which find will start looking for files recursively moving down the file tree
    • -type f - specifies I only want find to find files.
    • -regextype egrep - In this example I'm using regex to pattern match filenames, and this tells find what flavor of regex to use
    • -regex 'regex.here' - The regex to be used to pattern match against the filenames
    • -exec - exec is a way to redirect output in bash and use that output as a parameter in the subsequent command.
    • mv {} /path/to/new/directory/ - mv is just an example, you can use almost any command here. The important bit is {}, which is the placeholder for the parameter coming from find, in this case, a full file path. So this would read when expanded, mv /full/path/of/file/that/matches/the/regex.file /path/to/new/directory/
    • \; - This terminates the command. The semi-colon is the actual termination, but it must be escaped so that the current shell doesn't see it and try to use it as a command separator.
  • I used duckdns for years without any issues at all. Only reason I switched is because I'm using Pangolin and tunneling instead of exposing my IP directly.

  • That makes sense. I'll add the whitespace capture. The actual string only has one backslash, the second is to escape, though as I'm typing this, I'm thinking I can do a `fr"regex here" to eliminate the second backslash? I'll have to test this later when I have time.

    Thank you!

  • No apologies necessary! This is incredibly helpful! I found in the documentation how to format the message with the basicConfig, so I'm going to get rid of the logDateTime, move the logger out of main (didn't even think about how that would limit it to only main and not the other functions.), and test output to stdout vs the file defined in basicConfig.

    Gotta go to work, but will implement this later. Thank you!!

  • Can you explain your reasoning behind adding the whitespace regex? I'm guessing that's insurance in case the config file syntax changes with an app update. Thank you!

  • They started doing the thing that all shows are doing now. One, is dumbing down the plotlines in general, but the far more annoying thing is the trend of showing a flashback of a thing that literally happened five minutes ago in the show and here it is again to make it super obvious that this was the super sneaky thing that they did to advance the plan/heist/plot.

    I fucking hate that trend. I'm not a second screen watcher. When I watch something, I watch it and pay attention because I want to be engaged in it. I know I'm in the minority and no amount of removed will change that, but it has caused me to abandon a lot of shows. Most recently Matlock and High Potential.

  • I did run across the qbittorrent-natpmp when I was looking into how to change the port via the api, but wanted to work out the process myself (not because of NIH, but for the learning of figuring it all out).

    I had no idea about the up/down command in gluetun! That's very nice. I'm going to look into that for sure.

    Thank you!

  • Programming @programming.dev

    Kinda proud of this python script I wrote

  • Music @lemmy.world

    VISIONS OF ATLANTIS - Hellfire

  • Linux @lemmy.ml

    Question About Bash Command Grouping Behavior in Script vs CLI

  • Linux @lemmy.ml

    Happy with my bash progress!

  • Linux @lemmy.ml

    Question: Can I use dd to clone my luks encrypted lvm os drive?

  • Linux @lemmy.ml

    In vim I can't type the ~ character

  • FoodPorn @lemmy.world

    I made Loukomedes (Greek donuts)

  • Linux @lemmy.ml

    Perl rename command works at cli but not in alias or bash script

  • Linux @lemmy.ml

    Edit: it's CentOS 7 (original: CentOS 3 on a self checkout?!?)

  • Linux @lemmy.ml

    Requesting Help with txg_sync Error I Can't Diagnose

  • Linux @lemmy.ml

    Kicked macOS to the Curb and Installed Asahi Fedora Gnome

  • FoodPorn @lemmy.world

    Spiced Lamb Taco on Fresh Naan

  • FoodPorn @lemmy.world

    Chicken Gyros

  • cats @lemmy.world

    My boy Brewster lounging

  • cats @lemmy.world

    Our very dramatic girl GG in her floofy bed.

  • FoodPorn @lemmy.world

    Made pita bread and then took the pita bread and made pita chips!

  • FoodPorn @lemmy.world

    Pineapple Coconut Curry and Fresh Naan

  • Linux @lemmy.ml

    What I Learned Using Linux This Week (05)

  • Linux @lemmy.ml

    What I Learned Using Linux This Week (04)