News for hackers. Stuff that matters.
Re:Techniques I Use to Create a Great User Experience for Sh... by ndsipa_pomu on Saturday September 14, 2024 @09:42AM (#41539736)
I had some similar thoughts when seeing the script.

For better user friendliness, I prefer to have the logging level determined by the value of a variable (e.g. LOG_LEVEL) and then the user can decide whether they want to see every single variable assignment or just a broad outline of what the script is doing.

I was taken back by the "print_and_execute" function - if you want to make a wrapper like that, then maybe a shorter name would be better? (Also, the use of "echo" sets off alarm bells).

Re:Techniques I Use to Create a Great User Experience for Sh... by irundebian on Saturday September 14, 2024 @10:11AM (#41539931)
What's so bad in using echo?
Re:Techniques I Use to Create a Great User Experience for Sh... by ndsipa_pomu on Saturday September 14, 2024 @10:29AM (#41540044)
Well, strokes beard, funny you should ask.

Have a look at https://mywiki.wooledge.org/BashPitfalls#echo_.24foo

Most of the time, "echo" works as you'd expect, but as it doesn't accept "--" to signify the end of options (which is worth using wherever you can in scripts), it'll have problems with variables that start with a dash as it'll interpret it as an option to "echo" instead.

It's a niche problem, but replacing it with "printf" is so much more flexible, useful and robust. (My favourite trick is using "printf" to also replace the "date" command).

Also, here's some more info on subtle differences between "echo" on different platforms: https://unix.stackexchange.com/questions/65803/why-is-printf...

Re:Techniques I Use to Create a Great User Experience for Sh... by irundebian on Saturday September 14, 2024 @10:45AM (#41540141)
Thank you!