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:]')
Sign up to request clarification or add additional context in comments.

1 Comment

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...
-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 Comments

No, it works. But he doesn't want to have it in console. He wants to store the new string in userInput.
This is not an answer but a comment.
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...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.