Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
soc:2009:lynusvaz:notes:scripting_doc:features_added [2009/08/07 10:15]
lynusvaz
soc:2009:lynusvaz:notes:scripting_doc:features_added [2009/08/16 00:16]
lynusvaz
Line 1: Line 1:
-The features mentioned here are NOT YET part of mainline gPXE, and are still under development. The modified code can be found in my git repository, in the [[http://​git.etherboot.org/?​p=people/​lynusvaz/​gpxe.git;​a=shortlog;​h=refs/​heads/​offset|offset]] branch. +=====Scripting Features===== 
- +The features mentioned here are NOT YET part of mainline gPXE, and are still under development. The modified code can be found in my git repository, in the [[http://​git.etherboot.org/?​p=people/​lynusvaz/​gpxe.git;​a=shortlog;​h=refs/​heads/​expt|expt]] branch.
-Scripting features:+
  
   - Identifiers   - Identifiers
   - Arithmetic evaluator   - Arithmetic evaluator
   - Quoting   - Quoting
-  - Return code 
   - Branches   - Branches
 +  - Return code
   - Loops   - Loops
  
-1. See the Identifiers section at: [[http://​etherboot.org/​wiki/​commandline]],​ for the basic syntax of an identifier. The new code allows identifiers to be '​nested',​ like:+====Identifiers==== 
 +See the Identifiers section at: [[http://​etherboot.org/​wiki/​commandline]],​ for the basic syntax of an identifier. The new code allows identifiers to be '​nested',​ like:
   set i 0   set i 0
   echo ${net${i}/​ip}   echo ${net${i}/​ip}
Line 18: Line 18:
   echo ${net$(${i}+1)/​ip}   echo ${net$(${i}+1)/​ip}
 will print the IP address of the net1 interface (if it exists). will print the IP address of the net1 interface (if it exists).
-Identifiers are expanded by placing them within ${}.+ 
 +====Arithmetic Evaluation==== 
 +Arithmetic expressions can be evaluated by placing them within $(). 
 +The following operators are supported (in order of decreasing precedence):​ 
 +  - ''​!,​ ~'' ​         (logical NOT and bitwise negation) 
 +  - ''​*,​ /, %'' ​      ​(multiplication,​ division, and modulo) 
 +  - ''​+,​ -'' ​         (addition, subtraction) 
 +  - ''<<,​ >>'' ​       (left- and right-shift) 
 +  - ''<,​ <=, >, >​='' ​ (inequality) 
 +  - ''​!=,​ =='' ​       (equal, not equal) 
 +  - ''&'' ​            ​(bitwise AND) 
 +  - ''​|'' ​            ​(bitwise OR) 
 +  - ''​^'' ​            ​(bitwise EX-OR) 
 +  - ''&&'' ​           (logical AND) 
 +  - ''​||'' ​           (logical OR) 
 +The == and != operators also act on strings. ​Identifiers are expanded by placing them within ${}.
 E.g.: E.g.:
   echo $(1 + 2)   echo $(1 + 2)
Line 29: Line 44:
   1   1
  
-2. Arithmetic expressions can be evaluated by placing them within $(). +====Quoting====
-The usual C operators (except assignment) are supported with their usual precendence:​ +
-Operators, in order of decreasing precedence:​ +
-  - !, ~          (logical NOT and bitwise negation) +
-  - *, /, %       ​(multiplication,​ division, and modulo) +
-  - +, -          (addition, subtraction) +
-  - <<, >> ​       (left- and right-shift) +
-  - <, <=, >, > ​(inequality) +
-  - !===        ​(equal,​ not equal) +
-  - &             ​(bitwise AND) +
-  - |             ​(bitwise OR) +
-  - ^             ​(bitwise EX-OR) +
-  - && ​           (logical AND) +
-  - ||            (logical OR) +
-The == and !operators also act on strings. +
- +
-3. Quoting:+
 The \ is used as an escape character. The following sequences are recognised: The \ is used as an escape character. The following sequences are recognised:
   * \<​space>​ Treats the space as part of the command-line argument   * \<​space>​ Treats the space as part of the command-line argument
Line 70: Line 69:
   Hello   Hello
   World   World
 +  Hello World
   It's good to see you!   It's good to see you!
  
-4. Branches:+====Branches====
 The keywords if, else and fi are used to branch command execution: The keywords if, else and fi are used to branch command execution:
   if <​condition>​   if <​condition>​
Line 90: Line 90:
       <backup statements>​ #​Call this statement sequence B       <backup statements>​ #​Call this statement sequence B
   done   done
-The statements in sequence A are executed one by one. If any of them fails, execution branches immediately to sequence B. If all the statements in sequence A are executed successfully,​ execution skips sequence B.+The statements in sequence A are executed one by one. If any of them fails, execution branches immediately to sequence B. If all the statements in sequence A are executed successfully,​ execution skips sequence B, and continue after the done statement.
  
 E.g.: E.g.:
Line 109: Line 109:
 will attempt to boot using the given kernel and initrd. If any of the three commands fail, it displays a message. will attempt to boot using the given kernel and initrd. If any of the three commands fail, it displays a message.
  
-4. The return code of the previous statement can be checked using the ${rc} variable.+====Return Code==== 
 +The return code of the previous statement can be checked using the ${rc} variable.
 A value of 0 means that the command completed successfully,​ while any other value means the command was not successful. A value of 0 means that the command completed successfully,​ while any other value means the command was not successful.
  
Line 120: Line 121:
   fi   fi
  
-6. While and for loops have been added:+====Loops==== 
 +You can use while and for loops as:
   while <​condition>​   while <​condition>​
   do   do
Line 150: Line 152:
   done   done
 displays: displays:
-  0 +  ​i = 
-  1 +  ​i = 
-  2 +  ​i = 
-  3 +  ​i = 
-  5 +  ​i = 
-  18 +  ​i = 18 
 +A break statement will exit a loop, and a continue statement will start the next iteration of the loop. 
 +  for i in 1 2 3 4 5 6 
 +  do 
 +        if $(${i} == 3) 
 +              continue 
 +        fi 
 +        echo 'i =' ${i} 
 +        if $(${i} == 4) 
 +              break      #This will exit the for loop, not just the if branch 
 +        fi 
 +  done 
 +displays: 
 +  i = 1 
 +  i = 2 
 +  i = 4
  

QR Code
QR Code soc:2009:lynusvaz:notes:scripting_doc:features_added (generated for current page)