>_ IzzyLab

Hands-on task

This task is step 9 of the course “tmux: sessions you never lose”

Read the pane output

medium~10 min

Create a background tmux session calc, use send-keys to make it multiply the two numbers from /root/factors.txt, then capture the pane contents and write the resulting number to the file /root/result.txt. You must read the result from the tmux pane, not compute it some other way.

What you'll practise:
  • tmux
  • capture-pane
  • send-keys
  • escaping
  • grep

Topic breakdown

This task ties together two tmux mechanisms: programmatically typing a command into a session (as in previous tasks) and capturing what's shown on the pane's screen. The pane contents are a buffer with the prompt, the echoed command, and its output; you can dump it to stdout and pull out the line you need with a filter like grep. A separate pitfall is shell special characters (for example * for multiplication) — when passing the command they must be escaped, otherwise the shell will expand them before the computation even happens.

What's checked

  1. result captured from the pane
  2. the calc pane shows the result of the computation

What it looks like