The correct way to implement your code is
y="HELLO"
val=$(echo "$y" | tr '[:upper:]' '[:lower:]')
string="$val world"
This uses $(...)
notation to capture the output of the command in a variable. Note also the quotation marks around the string
variable -- you need them there to indicate that $val
and world
are a single thing to be assigned to string
.
If you have bash
4.0 or higher, a more efficient & elegant way to do it is to use bash
builtin string manipulation:
y="HELLO"
string="${y,,} world"