Tuesday 21 October 2014

Converting a line to line Letter Case in bash script.

Here is an example of converting a sentence to Letter Case.

Suppose there is a string "hello world how are you" so when you convert it it should be converted to "Hello World How Are You". I have tried a bash script which does the same after taking an input from the user. It exclusively uses upper case conversion formula ^^ and substring formula ${string:startpos:length.}.

Just follow the example 

#!/bin/bash
# Author Subhroneel Ganguly
# Date 21.10.2014
echo Enter String :
read line
lettercase=""
for wrd in $line
do
let size=${#wrd}
firstchar=${wrd:0:1}
firstchar=${firstchar^^}
lettercase=$lettercase$firstchar${wrd:1:$size}" "
done
echo $lettercase

If you want more tutorials subscribe to my channel : https://www.youtube.com/subhro190776.

No comments: