ash and shell syntax (was Re: echo question)
DaviD W. Sanderson
dws at margay.cs.wisc.edu
Sun Mar 10 08:24:17 AEST 1991
Ash user cks at hawkwind.utcs.toronto.edu (Chris Siebenmann) writes:
> There is also my personal favorite: ash, ...
...
>It's small, fast, and (IMHO) pretty damn nice; ...
I looked at ash a while back, and was similarly impressed by it.
However, I did not adopt it because it did not support the alternative
syntax of the "for" and "case" statements in sh and ksh. (I happened
onto the syntax while browsing through a system script, identity now
forgotten.)
What is the alternative syntax? The "in" and "esac" in a case
statement may be replaced with braces ("{" and "}"), as may the "do"
and "done" in a "for" statement. Note that mixing the two notations
(e.g. using "do" with "}") is not allowed. (Note also that it does not
make sense to allow this sort of replacement in an "if" or a "while" or
an "until" statement, since the tested condition in those statements is
an arbitrary number of commands, which may of course contain braces.)
This capability has been in every sh and ksh I have ever used, on both
System V and BSD-derived systems. (With the variety of UNIX systems
being what it is, there are probably versions of sh where it doesn't
work, but I've never found one.) I find the alternative syntax
pleasant to use since the matching brace can be found easily with the %
command in vi, making it easier (for instance) to find the other end of
a large case statement.
Here is a short example script to illustrate:
--------------------------------------------------
#!/bin/sh
for i in 1; { echo works; }
for i in 1; {
echo with
}
for i in 1
{
echo "'for'"
}
case 1 { 1) echo works;; }
case 1 {
1) echo with;;
}
case 1
{
1) echo "'case'";;
}
--------------------------------------------------
I tried to correspond with the author of ash about this, but I never
had any response to my mail. Incidently, the last time I paid any
attention to bash, it supported some of these variations but not
others. I have not investigated the shells recently posted in
alt.sources (zsh, P.D. ksh) to see if they support these alternative
forms.
--
___
/ __\ U N S H I N E DaviD W. Sanderson
| | | I N E dws at cs.wisc.edu
_____| | |_____ ________
\ / \ |__/ /////__ Fusion Powered Locomotives Made to Order
\____/ \__|_/ \\\\\______ (TARDIS model available at extra cost)
More information about the Comp.unix.shell
mailing list