I didn’t realize that. Thanks for pointing that out!
- 0 Posts
- 138 Comments
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
IFSwhen executing for loops like this.IFSstands 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
lsoutput 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 thelscommand 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
ihere, as you said could be anything. You could sayfor file in $LIST;orfor 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 variableiin 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 variablei.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, thedonestatement tells bash that this is the end of the for loop. So any commands after thedonestatement 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 runLIST=$(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.
harsh3466@lemmy.mlto
Selfhosted@lemmy.world•What DDNS providers you guys recommend?English
2·1 month agoI 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.
Sorry, typo. It’s Play:sub
Unfortunately, yes
Android or iOS?
On android I found symphonium to be a great app to use with my navidrome server. On iOS, play:sub was the best experience I found
What’s the actual story behind this meme template?
harsh3466@lemmy.mlto
Selfhosted@lemmy.world•The 'if this goes down, I riot' self-hosted appEnglish
51·2 months agodeleted by creator
harsh3466@lemmy.mlto
Selfhosted@lemmy.world•jotty·page - Checklists & Notes made it easyEnglish
5·3 months agoThis looks awesome. I’m going to check it out.
harsh3466@lemmy.mlto
Open Source@lemmy.ml•Introducing Ultimate Audiobooks, the one stop shop for file cleaning
5·4 months agoFWIW, they don’t have an api. It’s on their long term roadmap.
harsh3466@lemmy.mlto
Selfhosted@lemmy.world•Forgejo fills up hard drive with repo-archivesEnglish
2·5 months agoI don’t know the specifics but forgejo is a gitea fork. There was/is some controversy around gitea governance and movent towards prioritizing a closed source paid/private versions of gitea.
Again, I don’t know details, just very broad strokes. I chose forgejo because it’s under active Foss development and I didnt want to deal with potentially going with gitea and then having to abandon it later for whatever reason might develop.
harsh3466@lemmy.mlto
Selfhosted@lemmy.world•Forgejo fills up hard drive with repo-archivesEnglish
12·5 months agoAnd I totally understand that. These AI crawlers really suck.
harsh3466@lemmy.mlto
Selfhosted@lemmy.world•Forgejo fills up hard drive with repo-archivesEnglish
311·5 months agoNot saying this is an option for you, only that I kept my forgejo instance private to avoid dealing with this AI crawler bullshit. I hope you find a good solution.
harsh3466@lemmy.mlto
Linux@programming.dev•The Quiet Revolution: GNU/Linux Crosses 6% Desktop Market Share—And It’s Just the Beginning
5·5 months agoTo be clear, flatpaks from flathub. Fedora has their own flatpak repository, and those are not the flatpaks you are looking for.
harsh3466@lemmy.mlto
Self Hosted - Self-hosting your services.@lemmy.ml•Absolute noob here, can I host my own contacts and calendar syncing service to ditch google?
23·5 months agoAbsolutely. There are different options.
If you want something simple, just contacts and calendar, check out Radicale. I’ve been running radicals for years and its great.
If you want something more like a whole google suite replacement (contacts, calendar, drive, docs, photos, etc), look at Nextcloud
harsh3466@lemmy.mlto
Selfhosted@lemmy.world•Your favourite piece of selfhosting - Part 1 - Operating SystemEnglish
10·6 months agoI’ve been using Ubuntu server on my server for close to a decade now and it has been just rock solid.
I know Ubuntu gets (deserved) hate for things like snaps shenanigans, but the LTS is pretty great. Not having to worry about a full OS upgrade for up to 10 years (5 years standard, 10 years if you go Ubuntu pro (which is free for personal use)) is great.
A couple times I’ve considered switching my server to another distro, but honestly, I love how little I worry about the state of my server os.
harsh3466@lemmy.mlto
Selfhosted@lemmy.world•how are my fellow peeps hosting your music collection these days?English
2·7 months agoI’ll give ultrasonic a try. Thank you.

Is WordPress running in docker or on the host is?
What you could do is set up and NFS or smb share on the ote other server, move all the media to that share on the file server and then mount the NFS/b share to the folder on the WordPress server.
Set up the NFS/smb share to mount at boot. WordPress shoudnt wvwn notice the difference.