Variations across unices

Ben Cranston zben at umd5.UUCP
Thu Jun 19 06:32:26 AEST 1986


About a week ago the following shell script was posted to net.jokes:

> # encrypt/decrypt a rot13 file
> # usage: rot13 file   or   command | rot13
> eval tr '"[A-Z][a-z]" "[N-Z][A-M][n-z][a-m]"' ${1:+'<$1'}
                                                   ^
What good is this colon?  We were speculating that it might serve to
terminate a numeric expression a la ${foo+bar-1:+defalt} but were not
able to get this shell script to work until the colon be removed.

We also had to remove the [square brackets] for it seems that "tr" on this
system not only doesn't need them but treats them as normal characters!
On this (BSD) system the following two scripts do seem to work:

#! /bin/sh
# encrypt/decrypt a rot13 file
# usage: rot13 file  or  command | rot13
eval tr '"A-Za-z" "N-ZA-Mn-za-m"' ${1+'<$1'}

#! /bin/sh
# encrypt/decrypt a rot13 file
# usage: rot13 file  or  command | rot13
echo tr 'A-Za-z N-ZA-Mn-za-m' ${1+'<$1'}

Are there in fact variant unices that require the [square brackets] 
on "tr" commands and allow integer expressions in ${parm+defalt} lists?

Or is this just somebody's idea of a bad joke?

-- 
                     umd2.UMD.EDU  Kingdom of Maryland Sperrows 1100/92
Ben Cranston  zben @ umd5.UUCP     {seismo!umcp-cs,ihnp4!rlgvax}!cvl!umd5!zben  
                     umd2.BITNET



More information about the Comp.unix mailing list