user1448015
user1448015

Reputation: 11

bash - user input - variable

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?

Upvotes: 0

Views: 399

Answers (2)

jordanm
jordanm

Reputation: 34934

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/

Upvotes: 4

Wug
Wug

Reputation: 13196

This ought to do it.

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

Read up on variable assignment in bash.

Upvotes: 2

Related Questions