1

What is the proper way to convert first character of a string from upper to lower case in bash on Mac OS I am not on Bash 4 version to convert string by following command

$string="Hello"
echo ${string^}

Is there any other alternative way to do it? Tried these commands too sed -e 's/./\L&/' or sed -e 's/^./\L&\E/'but didn't worked.

Any kind of help is appreciated. Thanks.

user4150758
  • 384
  • 4
  • 17
  • How can it be a duplicate? Firstly the question is about converting them to a lowercase and secondly, none of those answers solve it. @inian – user4150758 Jul 11 '18 at 20:48
  • 1
    Using the first answer, just swap the order of `:lower:` and `:upper:`. There's a comment below the second answer that says how to change it to lowercase. – Barmar Jul 11 '18 at 20:58
  • If you can't figure out how to reverse the conversion direction of those answers, I don't think you're cut out to be a programmer. You can't always find exact solutions to your problem, you need to learn to generalize and extrapolate. – Barmar Jul 11 '18 at 20:59
  • @Barmar I didn't said I was a programmer. I am learning things to be a programmer. Still I don't count this as a duplicate, but it can be as a reference. – user4150758 Jul 11 '18 at 21:04
  • We don't require them to be exact duplicates for this close reason, just that they're similar enough that the answers are the same or can be easily extrapolated. – Barmar Jul 11 '18 at 21:05
  • You shouldn't need to be an expert to understand that you can easily change `tr '[:lower:]' '[:upper:]'` to `tr '[:upper:]' '[:lower:]'` to convert in the opposite direction, it should be obvious. – Barmar Jul 11 '18 at 21:07
  • `${myvar,}` will convert the first character of `$myvar` to lowercase – Tuhin Paul Jun 21 '19 at 18:06

0 Answers0