Junos Automation (Scripting)
Reply
Contributor
jslaven
Posts: 21
Registered: ‎05-19-2011
0

Conditionally Assigning Variable Values

I am trying to complete the Try It Yourself on page 37 of This Week Deploying Junos Automation but I am getting the following error and don't know why.  My script is below.

 

jeff@R1# run op add-sub ?
error: ^

error: error: /var/db/scripts/op/add-sub.slax: 1 error detected during parsing

error: error reading stylesheet: add-sub.slax

Possible completions:
  <[Enter]>            Execute this command
  <name>               Argument name
  detail               Display detailed output
  |                    Pipe through a command
/var/db/scripts/op/add-sub.slax:51: error: /var/db/scripts/op/add-sub.slax:50: parse error, unexpected T_VAR, expecting L_EOS or L_UNDERSCORE before '$math-type':


==========

version 1.0;

ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";

import "../import/junos.xsl";

/* These variables defines the CLI help text */
var $arguments = {
  <argument> {
      <name> "oper";
      <description> "Math operator";
  }
  <argument> {
      <name> "num1";
      <description> "First number";
  }
  <argument> {
      <name> "num2";
      <description> "Second number";
  }
}

/* Command line arguments */
param $oper;
param $num1;
param $num2;

match / {
<op-script-results> {

var $math-type = {
 if ( $oper == "+" ) {
  expr $num1 + $num2;
}
else if ( $oper == "-" ) {
  expr $num1 - $num2;
}
else {
 expr "unknown";
 }
}

/* Output */
   <output> $user _ ": " $math-type;

 }
}

Recognized Expert
Mattia
Posts: 198
Registered: ‎03-17-2010
0

Re: Conditionally Assigning Variable Values

Hi Jslaven,
it looks like you forgot to insert an underscore in the <output> part, before the $math-type variable!
.................................................................................
JNCIP-ENT, JNCIP-SEC, JNCIS-SP
(If this post helped you, please mark it as an "Accepted Solution"; kudos are also appreciated!)


Contributor
jslaven
Posts: 21
Registered: ‎05-19-2011
0

Re: Conditionally Assigning Variable Values

Mattia, thank you for your reply.

Copyright© 1999-2013 Juniper Networks, Inc. All rights reserved.