[lug] simple bash Q.

D. Stimits stimits at idcomm.com
Sat Mar 9 15:20:54 MST 2002


Peter Hutnick wrote:
> 
> On Saturday 09 March 2002 03:03 pm, D. Stimits wrote:
> > I know there is a simple way in bash scripts to convert a string to all
> > uppercase or all lowercase, but I can't seem to find the script version
> > (I see key bindings listed for interactive bash sessions). What would
> > the "toupper" and "tolower" be if I have a variable:
> > myvar="TeStMe"
> 
> I don't know if bash has some cool-guy built in way to do this, but I would
> just use seds transliterate feature.
> 
> >From the sed man page:
> 
>        y/source/dest/
>               Transliterate the characters in the  pattern  space
>               which appear in source to the corresponding charac­
>               ter in dest.
> 
> So you might want to do "sed
> y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/" to switch to lower
> and just swap source and dest to switch to upper.
> 
> sed rules.

If I don't find a built-in way from bash I'll go ahead and use this. It
seems strange though that bash wouldn't have something already for such
a basic string processing command. On the other hand, maybe it'll give
me an excuse to become a bit more familiar with sed.

D. Stimits, stimits at idcomm.com

> 
> -Peter
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug



More information about the LUG mailing list