His version will do nested replacements, eg if $FOO expands to the text $BAR, then that will in turn be expanded as well. I don't know if that's particularly desirable, though.
Makeshifts last the longest.
| [reply] |
Aristotle,
BUU and I discussed this over in #perl independent of these posts. I understand what his version is doing but I think that is the "wrong" thing to do.
$ FOO="asdf"
$ BAR="$FOO you"
$ echo $BAR
asdf you
$ FOO=123
$ echo $BAR
asdf you
There is only one level of expansion in environmental variables so I would assume that is what is intended for this script. I did make the caveat that it was fragile with regards to the assumptions I made and that it would have to be modified accordingly.
| [reply] [d/l] |
I think it is a bad idea as well. What happens if FOO='$BAR' and BAR='$FOO', f.ex? How do you include a literal $ character in the value of a variable without breaking anything? There are just too many unpredictables. If there's only a single level of replacement, none of these things becomes an issue. Of course, indirection becomes impossible, but that should be implemented properly at the top level, with a well-defined syntax; at that point you are on your way to a full-fledged templating system or even a complete language.
Makeshifts last the longest.
| [reply] |