D-Link DSN-5000-10 CLI User's Guide for DSN-1100-10 - Page 41
Advanced Scripting Concepts - dollar bill
UPC - 790069324024
View all D-Link DSN-5000-10 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 41 highlights
3.4.3 Advanced Scripting Concepts The CLI provides the ability to perform environment variable substitution. Variable substitution is the process of replacing a reference to the name of a variable with its actual value. Variable substitution is useful in Python, Perl, Bash, or other scripts that invoke predefined CLI script files and perform substitution at runtime. The substitution syntax is ${varName}, with the information typed between the curly brackets specifying the variable name. Any time you use this syntax in a command line, the CLI expects the variable name in curly brackets to be the name of a variable. If you want the dollar sign preceding the first curly bracket to be interpreted as just a simple dollar sign, precede it with the backslash (\) "escape" character. Example 1: The following example shows how variable substitution might work with a bash script. In this example, assume that a bash script has the following lines: #!/bin/bash export VolName="MyNewVolName" cli2 -x DeleteVolume export VolName="Zeus" cli2 -x DeleteVolume Also, assume that DeleteVolume.cli contains the following line: VolumeList.Volumes[${VolName}].Delete In this example, ${VolName} will be replaced with the volume named Zeus, which will be deleted. Example 2: The following example shows how the backslash character can be used to have the CLI interpret a dollar sign character as just a simple dollar sign. In this example, assume that an ENV variable called envvar equals ABC. In this case, abc\${envvar} becomes abc${envvar}, while abc${envvar} becomes abcABC. Command Line Interface User's Guide 31