CertGrid CertGrid
Hands-on Lab·Red Hat Certified System Administrator

Command Output in Shell Scripts

The last of the four scripting objectives, and the one that turns a script from a list of commands into something that reacts. Command substitution, arithmetic on captured values, branching on exit status and reading output into an array are all run here.

Shell Scripts Guide 65 of 67 Intermediate

Written against the versions above. `$(command)` is preferred over backticks: it nests without escaping and is easier to read. Both work and the exam accepts either. Command substitution **strips trailing newlines**, which is usually what you want and occasionally is not.

Every command on this page runs on RHCSA-A01.
Server NameIP AddressOSRolesCPURAMHDD
RHCSA-A01192.168.0.31RHEL 10.0 (Coughlan)Practice node (graded) - spare /dev/sda2 Core4 GB50 GB + 15 GB

Before you start

  1. Capturing, counting and branching

  2. Two syntaxes, and what gets stripped

  3. All four objectives in one script

Official sources