Unix Shell - Re: convert 1st char of a word to uppercase

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > April 2005 > Re: convert 1st char of a word to uppercase





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: convert 1st char of a word to uppercase
Chris F.A. Johnson

2005-04-25, 5:53 pm

On Mon, 25 Apr 2005 at 04:03 GMT, Hans Horn wrote:
> Group,
> is there a simple way to convert just the first char of a word to uppercase?


With a POSIX shell, no external command is necessary:

case $word in
a*) l=A ;; b*) l=B ;;
c*) l=C ;; d*) l=D ;;
e*) l=E ;; f*) l=F ;;
g*) l=G ;; h*) l=H ;;
i*) l=I ;; j*) l=J ;;
k*) l=K ;; l*) l=L ;;
m*) l=M ;; n*) l=N ;;
o*) l=O ;; p*) l=P ;;
q*) l=Q ;; r*) l=R ;;
s*) l=S ;; t*) l=T ;;
u*) l=U ;; v*) l=V ;;
w*) l=W ;; x*) l=X ;;
y*) l=Y ;; z*) l=Z ;;
esac
cword=$l${word#?}

--
Chris F.A. Johnson <http://cfaj.freeshell.org>
========================================
==========================
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
<http://www.torfree.net/~chris/books/ssr.html>
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com