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

Shell Script Arguments

One objective, $1 and $2 by name. The parts worth practising are the argument count check that makes a script usable, and the difference between "$@" and $*, which is invisible until an argument contains a space.

Shell Scripts Guide 64 of 67 Beginner

"$@" expands to one word per argument, preserving spaces inside each. $* joins them into a single string and then word-splits it. "$@" with the quotes is almost always what you want, and the quotes are not optional.

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

This guide includes

Use this for one objective that names $1 and $2 directly. This matters because refusing to run without arguments is part of the job - and "$@" and $* differ in a way that only shows up on multi-word arguments.

Before you start

  1. The parameters

  2. Refusing to run without them

  3. `"$@"` and `$*`

Official sources