bash is an unacceptable scripting language
Conversation
Notices
-
Emacsen (emacsen@emacsen.net)'s status on Sunday, 05-Jun-2022 14:01:36 CEST Emacsen -
Ekaitz Zárraga 👹 (ekaitz_zarraga@mastodon.social)'s status on Sunday, 05-Jun-2022 14:01:35 CEST Ekaitz Zárraga 👹 @emacsen those who don't know bash use to say those things 😉
-
Ekaitz Zárraga 👹 (ekaitz_zarraga@mastodon.social)'s status on Sunday, 05-Jun-2022 14:02:12 CEST Ekaitz Zárraga 👹 @emacsen (it is pretty horrible, yeah, for anything that is not a supershort thing)
-
Emacsen (emacsen@emacsen.net)'s status on Sunday, 05-Jun-2022 14:03:18 CEST Emacsen I can't get bash to easily let me for loop through files that contain spaces and single quotes.
-
Ekaitz Zárraga 👹 (ekaitz_zarraga@mastodon.social)'s status on Sunday, 05-Jun-2022 14:03:18 CEST Ekaitz Zárraga 👹 @emacsen for that you need to understand the expansions:
for i in *; do...
works perfectly.
If you try to iterate over `ls`, that's a problem
-
Ekaitz Zárraga 👹 (ekaitz_zarraga@mastodon.social)'s status on Sunday, 05-Jun-2022 14:05:31 CEST Ekaitz Zárraga 👹 @emacsen the thing is that Bash applies word separation after command substitution, but not after directory expansion. It has a good reason to do that, but if you try to deduce these things from other languages it's pretty hard to do.
-
Ekaitz Zárraga 👹 (ekaitz_zarraga@mastodon.social)'s status on Sunday, 05-Jun-2022 14:07:09 CEST Ekaitz Zárraga 👹 @emacsen yes, and the directory expansion that the shell does is split properly.
If you read `man bash` everything is explained there but it's a pretty long file :) (i've read that before)Also the book "Pro bash programming" is easy to follow and explains these kind of things
-
Emacsen (emacsen@emacsen.net)'s status on Sunday, 05-Jun-2022 14:07:10 CEST Emacsen ah right because the shell is already expanding it for you.
I'm probably going to end up switching this script to be a lua or python script. I just hoped to stay "simple".
-
Emacsen (emacsen@emacsen.net)'s status on Sunday, 05-Jun-2022 14:52:42 CEST Emacsen The glob helped... but now I get a weird one....
let's say I do
for i in "*.txt *.md"; do
runme $i
...it goes through the txt files, but then it sends "*.md" to runme!
-
Ekaitz Zárraga 👹 (ekaitz_zarraga@mastodon.social)'s status on Sunday, 05-Jun-2022 14:52:42 CEST Ekaitz Zárraga 👹 @emacsen i don't think that expansion is correctly thought. What are you trying to expand to?
-
Emacsen (emacsen@emacsen.net)'s status on Sunday, 05-Jun-2022 14:57:33 CEST Emacsen I have a directory of files, some of which may contain one type, or another type, I want to say "Go through some of these files, but not all of them, only the ones with the extension *.txt and *.md but not, say *.tex
-
Ekaitz Zárraga 👹 (ekaitz_zarraga@mastodon.social)'s status on Sunday, 05-Jun-2022 14:57:33 CEST Ekaitz Zárraga 👹 @emacsen using that expansion you are combining strings.
You have to use other kind of expansions...
?(*.md|*.txt) or something like that would be better I think.Read `man bash` under Pathname Expansion section.
But you might need to activate glob pattern support in the scripts (in the shell is automatically active) -
Ekaitz Zárraga 👹 (ekaitz_zarraga@mastodon.social)'s status on Sunday, 05-Jun-2022 15:08:37 CEST Ekaitz Zárraga 👹 @emacsen the main problem bash has is many of the things it does you can't extrapolate from other languages, so if you don't know it well it's really hard to deduce how to do things...
-
Emacsen (emacsen@emacsen.net)'s status on Sunday, 05-Jun-2022 15:08:38 CEST Emacsen Thanks! This is already taking me further.
I still may convert this whole thing to another language but this is helping for sure!
-