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.
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
Validate effective arguments, output destinations, and each operation’s result.
Reference: bash(1): shell expansion and pipelines · EX200 based on Red Hat Enterprise Linux 10