How to convert lower case variable into upper case?

Martin Weitzel martin at mwtech.UUCP
Thu Jan 31 08:02:54 AEST 1991


In article <553 at twg.bc.ca> bill at twg.bc.ca (Bill Irwin) writes:
>I  asked  for a way to convert the name of a uucp lock file  into
>its  upper  case counterpart /dev device name.  Since  you  don't
>know  which modem ports might be in use, those solutions that had
>a particular letter "wired" in have limited value.
>
>I  received  several  mailed responses.  The  simplest  and  most
>easily understandable (by me), provided by Stuart Hood, follows:
>
>case $modem in
>        i[1-9][a-z])
>        real_modem=i`echo $modem | sed 's/i//' | tr '[a-z]' '[A-Z]'`
>        ;;
>esac

Hmmm, judging from the numerous followups the original questions
seems to draw a lot of answers. As someone else allready metioned
the y-command of sed to simplify the above, I'll turn back from this
and related ways to solve the problem to another "no sub-processes"
solution. Like the original way with "case-in" the following has the
limitation that you must set up all the expected names in advance,
but this time as shell variables, not as case labels:

	i0p=i1P
	i1p=i1P
	i2p=12P
	....etc...

Then use eval 'real_modem='$modem .

Note that setting up the required variables can be also done in a loop:

	for i in 0 1 2 3 4 5 6 ......
	do
		eval 'i'$i'p=i'$1'P
	done

Another idea would be to avoid the variables and do it all in a loop:

	for i in 0 1 2 3 4 5 6 ......
	do
		case $modem in
		i${i}p) real_modem=i${i}P
		esac
	done
-- 
Martin Weitzel, email: martin at mwtech.UUCP, voice: 49-(0)6151-6 56 83



More information about the Comp.unix.shell mailing list