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:
Note
Under pdksh
and bash
, you must ensure that the equal sign (=
) does not have spaces before and after it.
To store a string in a variable, you can use the following:
Use 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:
Get Ubuntu Unleashed 2013 Edition: Covering 12.10 and 13.04, Eighth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.