0

Say I have something like

if [[ "$age" = "12" ]]; then
    "$age" = "twelve"
fi

This still returns the number itself. How can I make it become twelve?

2 Answers 2

4

Your syntax for assigning a variable is wrong. You can't have whitespace around the "=" and the variable being assigned should not be expanded with "$":

age="twelve"

The following is a good guide for learning basics and bash syntax: http://mywiki.wooledge.org/BashGuide/

Sign up to request clarification or add additional context in comments.

Comments

2

This ought to do it.

if [[ "$age" = "12" ]]; then
    age="twelve"
fi

Read up on variable assignment in bash.

1 Comment

I'm not sure what you mean. Going back to 12 from "twelve"? you should be able to use if [[ "$age" = "twelve" ]]; then age=12 fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.