[Gllug] Stories of using filters

Nix nix at esperi.org.uk
Mon Mar 21 14:41:00 UTC 2005


On Fri, 18 Mar 2005, Tethys stated:
> Nix writes:
>>> tr
>>
>>This one is really useful. Examples (all assuming LC_COLLATE="C"):
>>
>>echo "$something" | tr '[a-z]' '[A-Z]'  # converts to uppercase
>>
>>tr -d '\015' < something  # proof that `dos2unix' is a pointless command
> 
> And of course, not forgetting instant rot13:
> 
> 	echo "$something" | tr '[A-Ma-m][N-Zn-z]' '[N-Zn-z][A-Ma-m]'

Maximally paranoid/robust:

echo "x$something" | tr -c 2- | LC_COLLATE=C tr '[A-Ma-m][N-Zn-z]' '[N-Zn-z][A-Ma-m]'

>>> fmt
> 
> Handy, but see "par", which is orders of magnitude more powerful
> (and useful). In particular, the ability to retain leading quote
> characters/strings is a godsend:
> 
> 	http://www.nicemice.net/par/

Oh, lovely. Snarfed. :)

>>> split
>>
>>Another one I've never really used.
> 
> In the past it was handy for chopping files up into 1.44MB chucks so they
> would fit onto a bunch of floppies, but I don't tend to do that any more.

I used to use it for that, too, but it's been so many years since I last
used floppies for mass data transfer that I'd quite forgotten. (I think
I last did anything like that in 1995...)

>>You probably also want to read the chapter `Portable Shell Programming'
>>in the Autoconf manual, particularly the bit on `Limitations of Shell
>>Builtins' 
> 
> Agreed wholeheartedly. They tend towards the excessively paranoid when
> it comes to portability (which coming from me is saying something), but

That's understandable given their intended users --- configure scripts
had *better* be portable.

Some of the constraints in there (e.g. `no functions') are only of use
with 1980-vintage shells, which seems insane until you realise that Sun,
for one, was shipping such a shell as /bin/sh until *very* recently.

> if more people followed the conventions listed there, I might encounter
> fewer horribly broken and Linux specific scripts. That would be a good
> thing...

Oh yes.

Mind you, it doesn't have to be Linux-specific to be horribly broken.
Hideously bad idea of the day, from fontforge.sf.net:

    dnl guess directory
    AC_MSG_CHECKING(trying to find the freetype source directory -- be patient)
      FreeType2_TT_SRC_DIRs=`find / -name ttobjs.h -print 2>/dev/null |grep '[freetype[^/\]*2[^/\]*/src/truetype/ttobjs.h]' | sort -r | sed -e 's/ttobjs.h//'`
[...]

`You tried to do *what* in a configure script?'

LART LART LART

>>not everything it says necessarily matters (e.g. I've never seen a
>>shell on which ! doesn't work) but a lot of it is worth bearing in
>>mind, like the `echo "x$foo" | cut -c 2- | ...' convention.
> 
> Equally, I've never seen a shell where correct quoting doesn't solve
> this problem, or (in the last 15 years) a system where test didn't
> have a -z option.

ISC/Interactive Unix (*ick* *ick*) for one had this problem.

Mind you, Interactive is nearly fifteen years dead, and good
riddance... nice systems, shame about the OS. ;)

-- 
> ...Hires Root Beer...
What we need these days is a stable, fast, anti-aliased root beer
with dynamic shading. Not that you can let just anybody have root.
 --- John M. Ford
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list