5

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:]'
meteorBuzz
  • 3,110
  • 5
  • 33
  • 60

2 Answers2

13

You should store the output of your commands :

read userInput
userInput=$(echo "$userInput" | tr '[:upper:]' '[:lower:]')
Aaron
  • 24,009
  • 2
  • 33
  • 57
  • you're right. he was indeed missing the part where he sets the variable. for some reason, i thought he didn't need that part and had issues converting to lowercase... – yftse Jan 16 '16 at 11:17
-1

Ii'm surprised that doesn't already work...

Did you have trouble storing the value?

If so, you'd have to:

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

But it looks like a mac environment. What results are you getting?

Edit, added userInput=$() and restructured to better inquire.

Alfred Huang
  • 17,654
  • 32
  • 118
  • 189
yftse
  • 183
  • 6