Convert string to variable case

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

How can I “assign” or “change” an existing value read in a variable.

If the user enters a string IAmString, I would like to propInputsave the value IAmString. I just print to the console, for example, for the sake of.

read userInput
echo ${userInput} | tr '[:upper:]' '[:lower:]'
+4
source share
2 answers

You must save your echo output:

read userInput
userInput=$(echo "$userInput" | tr '[:upper:]' '[:lower:]')
+7
source

I am surprised that it still does not work ...

Having trouble saving the value?

If so, you need to:

userInput=$(echo ${userInput} | tr '[:upper:]' '[:lower:]')

But it looks like a mac environment. What results do you get?

Change, add userInput=$()and change it to find out better.

-1
source

Source: https://habr.com/ru/post/1624569/


All Articles