3 ms·
No, all the kinds of parameter expansion that exist in bash belong to 3 groups: 1. expansions introduced by the Bourne shell in 1979 2. expansions added by th
by adrian_b 5y ago
No, all the kinds of parameter expansion that exist in bash belong to 3 groups:
1. expansions introduced by the Bourne shell in 1979
2. expansions added by the Korn shell in 1988 (e.g. ${parameter#word} and ${parameter%word})
3. expansions added by the Korn shell in 1993 (e.g. ${parameter:offset:length}
and ${parameter/pattern/string})
There are no parameter expansions that have been introduced by bash.
I agree that the parameter expansions introduced by ksh93 are extremely useful in scripts.
The fact that they are not compliant with POSIX is a good reason to ignore POSIX compliance.
The POSIX compliant way is to use sed for substitutions and awk for substrings (even expr is not POSIX compliant), which results in much longer expressions in which it is easy to make mistakes, and in slower scripts, because external processes must be executed even for simple string expressions.
- joveian 5y agoAre the case modification and @operator in ksh also? @Q is the one I use on occasion.
- adrian_b 5y agoThere are a lot of uses for "@", most of which come from Bourne sh or from ksh. I assume that you refer to the "${PARAMETER@OPERATOR}" type of parameter expansion, which is mostly used to either replace invocations of tr for character conversions or to provide quoted strings. You are right that this kind of parameter expansion is specific to bash and I was wrong when I have said that there are no bash specific parameter expansions. "${PARAMETER@OPERATOR}" is the only exception that was introduced by bash and which has not been taken from the Bourne or Korn shells. I have forgotten about it, because I do not use it, precisely because it is the parameter expansion variant that is provided only by bash.