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

Written against the versions above. `"$@"` 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.0 (Coughlan)Practice node (graded) - spare /dev/sda2 Core4 GB50 GB + 15 GB

Before you start

  1. The parameters

  2. Refusing to run without them

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

Official sources