← RHCSA: RHEL 10 production administration
01 / 10 · 32 MIN

Tools, arguments, and reliable scripts

Interpret redirections, links, and arguments before automating an operation.

Concept and mechanism

The shell transforms a line into arguments and redirections before executing the program. In Bash, order matters: command >output.log 2>&1 first associates stdout with the file and then copies that destination to stderr. Reversing the order can leave errors on the terminal.

In loops, "$@" preserves each received argument; "$*" combines arguments into one quoted expansion. Capture or evaluate command status immediately because a later echo also changes $?. For log filtering, a start anchor and separator distinguish ERROR followed by a space from occurrences inside another message.

Guided application

In a financial batch, an output file’s existence does not prove processing finished. If the command fails, retain evidence and reconcile effects before retrying. Also inspect links: a hard link is another name for the same object; removing one name does not remove content while relevant references remain.

A relative symlink resolves its target from the directory containing the link, not the operator’s current directory. When a glob matches nothing, Bash can retain the literal pattern if nullglob and failglob are disabled. Make these conditions explicit in the script and rehearsal.

IN PRACTICE

If /srv/app/current points to releases/v2, the relative target starts at /srv/app. Rehearsing the script with a path containing spaces exposes quoting failures before the window.

Common pitfalls

Reading $? too late; splitting paths; reversing redirection order; resolving symlinks from the operator’s session.

Related topics: Software, RPM repositories, and Flatpak · Operations, targets, and persistent evidence

Take this idea with you

Validate effective arguments, output destinations, and each operation’s result.

Create account

Reference: bash(1): shell expansion and pipelines · EX200 based on Red Hat Enterprise Linux 10

Red Hat® and RHCSA are trademarks or registered trademarks of Red Hat, Inc. bigsavant.com is an independent preparation platform and is not affiliated with, associated with, sponsored, authorised or endorsed by Red Hat. Content and questions are original, are not official exam questions, and completing our tests does not award or guarantee any certification. Names are used only to identify the subject. All other trademarks belong to their respective owners.