[ale] Bash script question
Byron A Jeff
byron at cc.gatech.edu
Thu May 15 10:00:15 EDT 2003
>
> Christopher Fowler wrote:
> > The problem is that bash isn't really made for this type of work.
> >
> >
> >>>comma_count=$(echo $line | tr -cd , | wc -c)
> >
> >
> > Sure, it may work above, but you are relying on external
> > programs such as tr and wc to do some work for you. Nothing
> > I can tink of internal to bash will do this for you. I've
> > ran into problems of compatibility issues in the past using
> > external commands to process strings.
>
> I would think it would be highly unlikely to find an OS that contains a
> bourne shell equivalent shell (like bash) that did not have both tr and
> wc. I would include sed, awk and a number of other tools as well.
I don't think that's Christopher's point. It's not the fact that the tools
won't be available, but that the tools won't necessarily behave the same way.
Here's a simple example I've run into. bash has a built in echo command that
uses the -n flag to suppress the newline at the end. However the external
echo command often uses a -c to do the same thing. The net effect is that
sometimes you'll get strange behavior if you use the echo command.
Another example is that gnu tar changed the option to invoke bunzip2 from -y
to -j. My script that used this option had to be modified.
But the counter is that bash was designed as a glue language for all of the
tools that are available. It tries to fit into the standard minimalist toolset
that Unix has had from the very beginning. The only exceptions are when
efficiency are of concern. A perfect example of this is bash's math mode. It
can be up to 100 times faster than using the standard expr command. In addition
it has a much more intuitive interface in the fact that you don't have to
put in spaces between every word of the equation, no additional quoting is
necessary, and that variables don't need to be quoted. It's a real benefit.
But I think it's a bit unfair to complain that bash doesn't have all of this
built in, when in fact it was designed that way on purpose. Otherwise the
shell would become a huge monstrosity, kind of like Perl! ;-)
I've really been trying to force myself to learn python for scripting. But
the vast majority of the time when I want to put together something simple
and quick, I fall back to bash because it works.
BAJ
_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale
More information about the Ale
mailing list