This is an old revision of the document!
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: - Identifiers - Arithmetic evaluator - Quoting - Return code - Branches - 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: set i 0 echo ${net${i}/ip} will print the IP address of the net0 interface. 2. Arithmetic expressions can be evaluated by placing them within $(). The usual C operators (except assignment) are supported with their usual precendence. Also, string comparison is permitted. Identifiers are expanded by placing them within ${}. E.g.: echo $(1 + 2) set a 15 echo $(${a} * 3 + 5) echo $( ${net0/ip} != "" ) 3. Quoting: The \ is used as an escape character. The following sequences are recognised: * \<space> Treats the space as part of the command-line argument * \<tab> Ditto * \<newline> Concatenates the next line to the current line. Both the \ and the newline character are removed * \<any other character> Removes the special meaning of the character (if any) Within single-quotes, all characters lose their special meaning. Within double-quotes, the \ and $ retain their special meaning. E.g.: set message 'Hello World' echo '${message} = '${message} set message Hello\ \ World set message Hello\ World\ \#1 #'Hello World #1' is treated as a single argument echo 'Hello World' echo Hello \ World echo It\'s good to see you! 4. 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. 5. Branches: The keywords if, else and fi are used to branch command execution: if <condition> <statements> fi if <condition> <statements> else #optional <statements> fi A try-catch block is a special kind of branch. try <crucial statements> #Call this statment sequence A catch <backup statements> #Call this statement sequence B done The statements in sequence A are executed one by one. If any of them fails, execution branches immediately to sequence B. E.g.: if $( ${filename} == "") echo "No filename" else chain tftp://${server}//${filename} fi try kernel tftp://${server}//${kernel} initrd tftp://${server}//${initrd} boot catch echo "Oops: ${rc}" done 6. While and for loops have been added: while <condition> do <statements> done The while loop executes the statement block while the condition is true. for <variable> in <value list> do <statements> done The variable takes on each value in the value list one by one. E.g.: set i 0 while $( ${net${i}/mac} != "" ) do dhcp net${i} if $(${rc} == 0) chain tftp://${server}//${filename} fi set i $( ${i} + 1 ) done for i in 0 1 2 3 $(3 + 1) 5 do dhcp net${i} if $(${rc} == 0) chain tftp://${server}//${filename} fi done