Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert string in variable lower case [duplicate]

Tags:

bash

Using bash version 3.2.57(1)-release (x86_64-apple-darwin14)

How can I 're-assign' or 'change' the existing value read into a variable.

If the user inputs the string IAmString, I'd like propInput to store the value iamstring. I'm simply printing to the console just for example sake.

read userInput
echo ${userInput} | tr '[:upper:]' '[:lower:]'
like image 259
meteorBuzz Avatar asked Dec 24 '22 10:12

meteorBuzz


1 Answers

You should store the output of your commands :

read userInput
userInput=$(echo "$userInput" | tr '[:upper:]' '[:lower:]')
like image 78
Aaron Avatar answered Jan 03 '23 04:01

Aaron