Re:Shell Script Best Practices, from a decade of scripting t...
by tb_technical on Thursday October 27, 2022 @10:03AM
(#33357593)
Off topic. What's your opinion on Python?
I also write shell scripts, but I'm just curious what you would think about a comparison.
Re:Shell Script Best Practices, from a decade of scripting t...
by hnlmorg on Thursday October 27, 2022 @08:04PM
(#33365760)
I’m not fan of Python, however that’s down to personal preference rather than objective fact. If Python solves a problem for other people then who am into judge :)
Re:Shell Script Best Practices, from a decade of scripting t...
by rcthompson on Thursday October 27, 2022 @12:07PM
(#33359669)
Once of my favorite Perl features that has been disappointingly under-appropriated by other languages is quoting with q(...).
Re:Shell Script Best Practices, from a decade of scripting t...
by 6keZbCECT2uB on Thursday October 27, 2022 @01:00PM
(#33360592)
This means that you can even quote the delimiter in the string as long as it's balanced.
$X=q( foo() )
Should work if it's balanced. If you choose a different pair like []{} then you can avoid hitting collisions. It also means that you can trivially nest quotations.I agree that this qualified quotation is really underutilized.
Re:Shell Script Best Practices, from a decade of scripting t...
by pdntspa on Thursday October 27, 2022 @03:43PM
(#33362984)
This is one of my favorite features of Ruby!
Though Ruby makes it confusing AF because there are two quoting types for both strings and symbols, and they're different. (%Q %q %W %w %i) I can never remember which does which.... the letter choice feels really arbitrary.
Re:Shell Script Best Practices, from a decade of scripting t...
by pmarreck on Friday October 28, 2022 @12:19PM
(#33373500)
Elixir has something like this too, but even more powerful (you can define your own):
https://elixir-lang.org/getting-started/sigils.html#strings-...
Re:Shell Script Best Practices, from a decade of scripting t...
by pmarreck on Friday October 28, 2022 @12:17PM
(#33373466)
Ruby and Elixir both have features like this. Very sweet.
Elixir has sigils, which are useful for defining all kinds of literals easier, not just strings:
https://elixir-lang.org/getting-started/sigils.html#strings-...
You can also define your own. It's pretty great.
Shameless plug coming, it this has been a pain point for me too. I found the issue with quotes (in most languages, but particularly in Bash et al) is that the same character is used to close the quote as is used to open it.m. So in my own shell I added support to use parentheses as quotes in addition to the single and double quotation ASCII symbols. This then allows you to nest quotation marks.
https://murex.rocks/docs/parser/brace-quote.html
You also don’t need to worry about quoting variables as variables are expanded to an argv[] item rather than expanded out to a command line and then any spaces converted into new argv[]s (or in layman’s terms, variables behave like you’d expect variables to behave).
https://github.com/lmorg/murex