home *** CD-ROM | disk | FTP | other *** search
/ Chip 2008 June / CHIP-2008-06.iso / software / PowerShell / PowerShell_Setup_x86.msi / product.cab / about_Parsing.help_EN.txt < prev    next >
Encoding:
Text File  |  2007-10-29  |  3.5 KB  |  85 lines

  1. TOPIC
  2.     Parsing
  3.  
  4. SHORT DESCRIPTION
  5.     How the Windows PowerShell parses commands
  6.  
  7. LONG DESCRIPTION
  8.     When you enter a command at the command prompt, PowerShell breaks the 
  9.     command text into a series of segments called tokens and then determines 
  10.     how to interpret each one. For example, PowerShell breaks the following 
  11.     command into two tokens:
  12.  
  13.         Write-Host book
  14.  
  15.     The first token is "Write-Host," and the second token is "book."
  16.     PowerShell interprets each token separately, within the context of the 
  17.     command as a whole.
  18.  
  19.     When processing a command, the PowerShell parser operates in one of two 
  20.     modes:
  21.  
  22.     * Expression mode - Character string values must be contained in 
  23.       quotation marks. Numbers not enclosed in quotation marks are treated 
  24.       as numerical values (rather than as a series of characters).
  25.  
  26.     * Argument mode - Each value is treated as an expandable string unless 
  27.       it begins with one of the following special characters: dollar sign 
  28.       ($), at symbol (@), single quote (?), double quote ("), or an opening 
  29.       parenthesis ((). If preceded by one of these characters, the value is 
  30.       treated as a value expression.
  31.  
  32.     The following table provides several examples of commands processed in 
  33.     expression mode and argument mode and the results produced by those 
  34.     commands:
  35.  
  36.     Example            Mode       Result
  37.     ------------------ ---------- -------------------------
  38.     2+2                expression numerical value of "4"
  39.     Write-Output 2+2   argument   string value of "2+2"
  40.     Write-Output (2+2) expression numerical value of "4"
  41.     $a = 2+2           expression numerical value of "4"
  42.                                   (assigned to $a)
  43.     Write-Output $a    expression numerical value of "4"
  44.     Write-Output $a/H  argument   string value of "4/H"
  45.  
  46.     Every token can be interpreted as some kind of object type, such as 
  47.     boolean or string. PowerShell attempts to determine the object type from 
  48.     the expression. The object type depends on the type of parameter a command 
  49.     expects and on whether PowerShell knows how to convert the argument to the 
  50.     correct type. The following table shows several examples of the types 
  51.     assigned to values returned by the expressions:
  52.  
  53.     Example            Mode       Result
  54.     ------------------ ---------- -------------------------
  55.     Write-Output !1    argument   string value of "!1"
  56.     Write-Output (!1)  expression boolean value of "false"
  57.     Write-Output (2)   expression integer value of "2"
  58.  
  59.     When processing cmdlet parameters, PowerShell recognizes strings contained
  60.     in quotation marks as being different from strings not enclosed in 
  61.     quotation marks. For example, in the following command, -type is 
  62.     treated as a parameter name:
  63.  
  64.         Get-Command -type cmdlet
  65.  
  66.     In this case, "cmdlet" is the argument passed to the -type parameter. 
  67.     However, in the next example, -type is treated as an argument:
  68.  
  69.         Get-Command "-type" cmdlet
  70.  
  71.     PowerShell will attempt to use the "-type" value as an argument to the 
  72.     first positional parameter, while the "cmdlet" argument will be treated 
  73.     as a parameter name, causing the command to fail.
  74.  
  75. SEE ALSO
  76.     For information about command syntax, enter the following command at 
  77.     the PowerShell command prompt:
  78.  
  79.         help about_command_syntax
  80.  
  81.     For information about quotation rules, enter the following command:
  82.  
  83.         help about_quoting_rules
  84.  
  85.