How do i define a user variable in a shell script?
-
Variables store various data, integers & strings. No spaces between the variable name and the assignment.
A user-defined variable is one that you assign. It helps structure the script.
These are all variables. The last one is an array variable.
Myfruit=pineapple Mynumber=5 Myitems=(cheese butter flour eggs sugar) echo ${Myitems[1]}
The array can be accessed via the array index number. As shown on line 4.
echo ${Myitems[1]}
. Array variables allow you to assign multiple values.To print or access all the array values use
echo ${Myitems[*]}
© Lightnetics 2024