Skip to content

Output and input ​

Formats ​

Results print as XML by default: pretty-printed, coloured on a terminal, and without the <rpc-reply> wrapper around data. output changes the default, and --xml, --json or --raw change it for one command:

nnc
nnc lab> get-config running --filter xpath /ietf-system:system --json
nnc lab> get-config running --filter xpath /ietf-system:system --raw
nnc lab> output json
nnc lab> read /ietf-system:system
nnc lab> output xml
  • xml: the data, pretty-printed.
  • json: the result as plain data. Data from get, get-config and get-data is RFC 7951 JSON, typed by the device's YANG schema: numbers are numbers, and lists are arrays even with one entry (see Reading JSON). Other replies are converted without a schema.
  • raw: the <rpc-reply> exactly as received.
Output
nnc lab> get-config running --filter xpath /ietf-system:system --json
{
  "ietf-system:system": {
    "contact": "tutorial@example.net",
    "hostname": "lab1"
  }
}

Errors print as blocks on standard error, whatever the format; see Errors. Control characters in device data are shown escaped, so a device can't send commands to your terminal.

Result views ​

A few results have a view of their own, shown by default (--xml still shows the XML): diff and compare print one line per change, and get-data --with-origin one line per leaf with its origin. See Comparing datastores and Origins.

Showing it again ​

show-last shows the last result or error again, in any format, without asking the device again. --raw shows the reply exactly as received, which is the place to look when a quirk or the parser changed something:

nnc
nnc lab> get-config running --filter xpath /ietf-system:system/hostname
nnc lab> show-last --json
nnc lab> show-last --raw

Long results ​

On a terminal, a result taller than the screen goes through $PAGER (less -R if it isn't set). --no-page prints it straight through. Scripts never page. The terminal on this site has no pager, so it prints everything; scroll back to see it.

Files ​

> file writes a result to a file instead of the screen, and >> file appends to one. @file reads XML or JSON from a file wherever a command takes it. Save part of the configuration, change it, and send it back:

nnc
nnc lab> get-config running --filter xpath /ietf-system:system > system.xml
nnc lab> edit-config candidate @system.xml
nnc lab> diff

In this site's terminal, files live in the page's memory, and go when you reload it.

--edit opens $EDITOR on what a command last sent, to change and send again, on commands that take XML: edit-config --edit, rpc --edit.

Typing commands ​

  • Inline XML and JSON need no quoting. XML ends where its elements balance, and JSON (a word starting with {) where its braces do. Either may span lines: the prompt keeps reading until it's complete.
  • Quotes and \ work as in a shell. Inside [...] quotes are kept as typed, so YANG paths need no extra quoting.
  • # starts a comment.
  • Tab completes commands, options, values such as datastores and trace levels, target names, module names after /, named paths after @, and file paths. A second Tab lists the choices.
  • Up and Down step through history, and Ctrl-R searches it. history lists it. nnc keeps it between sessions; the terminal on this site keeps it in your browser.
  • Ctrl-C cancels the command in progress, and leaves the session open.

Help ​

help lists every command the session can run, grouped by layer; see Commands. help <command> shows one command's usage, options, the capabilities it needs and whether it changes state:

nnc
nnc lab> help
nnc lab> help get-data
nnc lab> help operations

Next ​

Released under the MIT Licence.