do not have to specify whether a variable is a number or a string, and so on.
Assigning a Value to a Variable
Suppose that you want to use a variable called lcount to count the number
of iterations in a loop within a shell program. You can declare and initialize
this variable as follows:
Command Environmentlcount=0 pdksh and bashset lcount=0tcshNOTE
Under pdksh and bash, you must ensure that the equals sign (=) does not
have spaces before and after it.To store a string in a variable, you can use the following:
Command Environmentmyname=Sedona pdksh and bashset myname=SedonatcshUse the preceding variable form if the string doesn’t have embedded spaces.
If a string has embedded spaces, you can do the assignment as follows:
Command Environmentmyname=“Sage” pdksh and bashset myname=“Sage”tcshAccessing Variable Values
You can access the value of a variable by prefixing the variable name with a
dollar sign ($). That is, if the variable name is var, you can access the
variable by using $var.