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:]'
0

2 Answers 2

13

You should store the output of your commands :

read userInput
userInput=$(echo "$userInput" | tr '[:upper:]' '[:lower:]')
1
  • 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
    Commented Jan 16, 2016 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.

3
  • No, it works. But he doesn't want to have it in console. He wants to store the new string in userInput. Commented Jan 16, 2016 at 11:16
  • 1
    This is not an answer but a comment. Commented Jan 16, 2016 at 11:16
  • it wasn't an answer, because i wasn't quite sure about the question. but i GUESS i see the question now? i still only now GUESS... that this was missing userInput=$(). Editing my "comment" now...
    – yftse
    Commented Jan 16, 2016 at 11:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.