Книги автора: Fedora™ Unleashed, 2008 edition
/ Книги автора: Fedora™ Unleashed, 2008 edition
/ honorato bonafe
Книга: Fedora™ Unleashed, 2008 edition
Assigning a Value to a Variable
Assigning a Value to a Variable
Assume 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 | Environment |
---|---|
lcount=0 |
bash |
set lcount=0 |
tcsh |
NOTE
Under 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:
Command | Environment |
---|---|
myname=Andrew |
bash |
set myname=Andrew |
tcsh |
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:
Command | Environment |
---|---|
myname="Andrew Hudson" |
bash |
set myname="Andrew Hudson" |
tcsh |
Оглавление статьи/книги
Похожие страницы
- Using Variables in Shell Scripts
- Accessing Variable Values
- Assignment Operators
- Anonymous Types (C# 3.0)
- Assignment
- Enumerations
- 8.5.2 Typical Condition Variable Operations
- Using Double Quotes to Resolve Variables in Strings with Embedded Spaces
- Access Variable Data Files in the
- Using Environment Variables
- Assigning Permissions
- Perl Variables and Data Structures