
Creating a Script File
114089 Rev. A 1-3
To prevent a variable from being expanded, enter two dollar signs ($$) before the
variable name, as shown in the following example:
setenv a blue
setenv b “My color is \$a”
echo $$b
My color is $a
appears on the user’s console.
You may embed variables in quoted strings, as shown in the previous example.
The following command line encloses the variable names
a and b in curly
brackets (
{ }) to separate the variable names from other data within the string.
echo “The sum of ${a}+1=${b}”
A variable name is usually a literal string of characters preceded by a dollar sign
($). The variable name can also be “built” dynamically when the script is executed
by using a combination of literal text and the text stored in other variables.
For example, if you have a variable named array_10, you can reference this
variable by entering
$array_10 on a command line. You can build this same
variable name by concatenating the text strings
array_ and 10. For example, if
you assign the variable index the value 10, using the command
let index = 10,
then you can build the variable name array_10 dynamically on the command line
using the following syntax:
${array_[$index]}. Notice the use of the square
brackets (
[ ]) within the variable name. Any literal text or variable name specified
within the square brackets is expanded first to replace any variables with their
values and then concatenated onto the preceding characters of the variable name.
To use square brackets, you must enclose the entire variable name being built in
brackets (
{ }).
Note: If the variable name is followed by a space or an end-of-line character
(carriage return), the brackets are optional.
Comentários a estes Manuais