linux poison RSS
linux poison Email

Bash Script: Convert String Toupper and Tolower

Here is a simple bash script which converts the given string to upper or to lower case.
feel free to copy and use this script:


Source:
cat toupper_tolower.sh
#!/bin/bash

echo -n "Enter the String: "
read String

echo -n "Only First characters to uppercase: "
echo ${String^}

echo -n "All characters to uppercase: "
echo ${String^^}

echo -n "Only First characters to Lowercase: "
echo ${String,}

echo -n "All characters to lowercase: "
echo ${String,,}


Output:
./toupper_tolower.sh
Enter the String: linuXPoisoN
Only First characters to uppercase: LinuXPoisoN
All characters to uppercase: LINUXPOISON
Only First characters to Lowercase: linuXPoisoN
All characters to lowercase: linuxpoison




1 comments:

adamo said...

Interesting usage of bash's $variable hacks. I would still do that with tr(1) for maximum portability among shells, unless I run a big bash-only script where your approach seems more handy.

Post a Comment

Related Posts with Thumbnails