Re:What the GNU?
by forgotpwd16 on Thursday September 30, 2021 @03:26PM
(#28710255)
For your example, in bash you can do
infile=input.png
outfile="${infile/.png/.jpg}"
Yes, supposing it exists and you've permissions for it, you can use sed. Do that a dozen times and the calls to an external process add up to a significant time. But the real advantage is being easier to write and work with.
https://wiki.ubuntu.com/DashAsBinSh
(Note that Systemd has since obviated most of that work.)
You may be writing very different shell scripts than the ones which I encounter. I'm not sure what you mean by "variable expansion", because variable expansion is portable. Something like 98%+ of all pattern replacement I see is something simple like replacing a suffix or prefix of a string. For example,
You can typically use sed for the complicated stuff.Above a certain level of complexity, I'd likely rewrite the script in Perl or Python, anyway. Or possibly Go.