> Hi all experts, I am new for unix shell scripting. Can anyone tell me how to
> change a filename from lowercase to uppercase by sh script? In addition, I
> only need to chnage the first letter of the filename i.e. "filename" --->
> All I know is the command-----tr "[a-z]" "[A-Z]"
> But this will change all letters to uppercase?
Separate the first letter, change that, then replace the first
letter of the filename with the upper-case letter.
These assume that the directory portion of the filename has
already been stripped off:
allbutfirst=`echo $filename | cut -c2-`
firstletter=`echo $filename | cut -c1`
capname=`echo $firstletter | tr '[a-z]' '[A-Z]'`$allbutfirst
With a POSIX shell, the first two lines can be replaced with:
With bash, no external commands are needed:
case $firstletter in
Chris F.A. Johnson http://cfaj.freeshell.org
My code (if any) in this post is copyright 2003, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License