Is there a way in Bash shell scripting so that I can convert a string into lower case string?
For example,
if $a = "Hi all"
I want to convert it to
$a = "hi all"
The are various ways: tr
AWK
Bash 4.0
Perl
Bash
|
|||||||||||||||||||||
|
In Bash 4: To lowercase
To uppercase
Toggle (undocumented)
Capitalize (undocumented)
Title case:
To turn off a Edit: Added "toggle first character by word" ( |
|||||||||||||||||||||
|
|
|||||||
|
tr:
AWK:
sed:
|
|||||||
|
Regular expressionI would like to take credit for the command I wish to share but the truth is I obtained it for my own use from http://commandlinefu.com. It has the advantage that if you
You can specify a directory in place of the dot(.) after the find which denotes current directory or full path. I hope this solution proves useful the one thing this command does not do is replace spaces with underscores - oh well another time perhaps. |
|||||||
|
Using Korn shell (ksh) typeset:
|
||||
|
Pre Bash 4.0 Bash Lower the Case of a string and assign to variable
|
||||
|
If using v4, this is baked-in. If not, here is a simple, widely applicable solution. Other answers (and comments) on this thread were quite helpful in creating the code below.
Notes:
|
|||
|
For Bash versions earlier than 4.0, this version should be fastest (as it doesn't fork/exec any commands):
technosaurus's answer had potential too, although it did run properly for mee. |
||||
|