I am reading a character from keyboard and converting it to uppercase and then displaying the character again. But this is showing error. How can I do this.
my code:-
read a;
a=echo $a | tr 'a-z' 'A-Z'
echo $a
I also tried this :-
read option;
eval $(awk -v option=$option '{print "a="toupper(option);}')
echo $a
If you want to store the result of a
back in a
, then you can do use command substitution:
read a;
a=$(echo $a | tr 'a-z' 'A-Z')
echo $a
This can be done natively in bash
as follows:
read a;
a="${a^^}"
echo "$a"
There is no need to invoke other commands like tr
, because bash
can do this itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With