Is there a way in bash to convert a string into a lower case string?
For example, if I have:
a="Hi all"
I want to convert it to:
"hi all"
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are various ways:
POSIX standard
tr
AWK
Non-POSIX
You may run into portability issues with the following examples:
Bash 4.0
sed
Perl
Bash
Note: YMMV on this one. Doesn’t work for me (GNU bash version 4.2.46 and 4.0.33 (and same behaviour 2.05b.0 but
nocasematchis not implemented)) even with usingshopt -u nocasematch;. Unsetting thatnocasematchcauses[[ "fooBaR" == "FOObar" ]]to match OK BUT inside case weirdly[b-z]are incorrectly matched by[A-Z]. Bash is confused by the double-negative ("unsetting nocasematch")! 🙂