DEV Community

Discussion on: Bash scripting for everyday actions

Collapse
 
moopet profile image
Ben Sinclair

Nice post.

My pedantry begins:

files = $(ls) isn't going to work because you can't have spaces around the assignment operator.

The script as you have it will do unexpected things if there are spaces in any of the path or filenames. I'd suggest using a find command and splitting the result by / instead, then using the resulting variables inside double-quotes.

It will also have issues if the filename starts with - because convert will interpret it as a flag.

Collapse
 
carminezacc profile image
Carmine Zaccagnino • Edited

I tested the script and had two versions of it at some point (one in the body of the text and one I was executing), I must have left snippets of the wrong one in, you're correct, I'll fix it right now, thank you very much for noticing that.
P.S.: The issue with spaces around the assignment is in the first part of the post, I didn't pay as much attention to that as I should have and I usually leave spaces intentionally around operators when programming, I fixed that already. It wasn't there in the final script because I paid more attention with that one because I was in my usual vim Bash-scripting environment and not in a GUI text editor writing Markdown like I was for the earlier section.
P.S. II: Regarding the potential issue with spaces in the path, I didn't think that was likely in the specific example, but I'll address that ASAP. I'll also credit you for your spot-on observations.
P.S. III: Regarding the issue with filenames starting with -, it actually would only be an issue if the first directory's name (the area) starts with -, and that is easily fixed by changing the command from convert ${picture} (...) to convert ./${picture} (...)