7412 |
@c FIXME: Eventually will become a chapter, as it is not related to |
@c FIXME: Eventually will become a chapter, as it is not related to |
7413 |
@c programming in M4 per se. |
@c programming in M4 per se. |
7414 |
|
|
7415 |
|
M4sh is aiming at producing portable Bourne shell scripts. For the time |
7416 |
|
being, it is not mature enough to be widely used. |
7417 |
|
|
7418 |
M4sh provides portable alternatives for some common shell constructs |
M4sh provides portable alternatives for some common shell constructs |
7419 |
that unfortunately are not portable in practice. |
that unfortunately are not portable in practice. |
7420 |
|
|
8463 |
Unix 4.0 and 5.0, will then replace it with an empty argument. To be |
Unix 4.0 and 5.0, will then replace it with an empty argument. To be |
8464 |
portable, use @samp{$@{1+"$@@"@}}. |
portable, use @samp{$@{1+"$@@"@}}. |
8465 |
|
|
8466 |
|
But that's not the end of the story. Zsh (3.x and 4.x), when emulating |
8467 |
|
the Bourne shell, does perform word splitting on @samp{$@{1+"$@@"@}}... |
8468 |
|
|
8469 |
|
@example |
8470 |
|
zsh $ @kbd{emulate sh} |
8471 |
|
zsh $ @kbd{for i in "$@"; do echo $i; done} |
8472 |
|
Hello World |
8473 |
|
! |
8474 |
|
zsh $ @kbd{for i in $@{1+"$@@"@}; do echo $i; done} |
8475 |
|
Hello |
8476 |
|
World |
8477 |
|
! |
8478 |
|
@end example |
8479 |
|
|
8480 |
|
@noindent |
8481 |
|
It is not clear whether this is a violation of the Bourne shell |
8482 |
|
standard, nevertheless, in this regard Zsh is different from all the |
8483 |
|
other shells. Of course Zsh handles @samp{"$@@"} properly, but we can't |
8484 |
|
use it portably... |
8485 |
|
|
8486 |
|
Fortunately, there is a workaround which relies on Zsh's ``global |
8487 |
|
aliases'': let it convert @samp{$@{1+"$@@"@}} into @samp{"$@@"} by |
8488 |
|
itself: |
8489 |
|
|
8490 |
|
@example |
8491 |
|
test -n "$@{ZSH_VERSION+set@}" = set && alias -g '$@{1+"$@@"@}'='"$@@"' |
8492 |
|
@end example |
8493 |
|
|
8494 |
|
|
8495 |
@item $@{@var{var}:-@var{value}@} |
@item $@{@var{var}:-@var{value}@} |
8496 |
@c Info cannot handle `:' in index entries. |
@c Info cannot handle `:' in index entries. |
8497 |
@c @cindex $@{@var{var}:-@var{value}@} |
@c @cindex $@{@var{var}:-@var{value}@} |
8510 |
otherwise some shells, such as on Digital Unix V 5.0, will die because |
otherwise some shells, such as on Digital Unix V 5.0, will die because |
8511 |
of a ``bad substitution''. |
of a ``bad substitution''. |
8512 |
|
|
8513 |
|
@sp 1 |
8514 |
|
|
8515 |
Solaris' @command{/bin/sh} has a frightening bug in its interpretation |
Solaris' @command{/bin/sh} has a frightening bug in its interpretation |
8516 |
of this. Imagine you need set a variable to a string containing |
of this. Imagine you need set a variable to a string containing |
8517 |
@samp{@}}. This @samp{@}} character confuses Solaris' @command{/bin/sh} |
@samp{@}}. This @samp{@}} character confuses Solaris' @command{/bin/sh} |
9167 |
done |
done |
9168 |
@end example |
@end example |
9169 |
|
|
9170 |
|
@noindent |
9171 |
|
But keep in mind that Zsh, even in Bourne shell emulation mode, performs |
9172 |
|
word splitting on @samp{$@{1+"$@@"@}}, see @ref{Shell Substitutions}, |
9173 |
|
item @samp{$@@}, for more. |
9174 |
|
|
9175 |
|
|
9176 |
@item @command{if} |
@item @command{if} |
9177 |
@c --------------- |
@c --------------- |
9178 |
@prindex @command{if} |
@prindex @command{if} |