Skip to content

Quoting and expansion

8 min

"$@" versus $@ versus "$*"

The distinction that is a live defect in most generated scripts.

A script's arguments are the positional parameters, and there are three ways to refer to all of them. They are not interchangeable.

"$@" gives one argument per positional, however each is spelled. $@ gives the same list and then re-splits it, so an argument containing a space becomes two. "$*" gives exactly one argument with them all joined.

A script that handles filenames correctly uses the first. A script written from memory uses one of the others.

Try this

With no arguments at all, "$@" expands to nothing — not to one empty argument. That is what makes command "$@" work when there are no arguments to pass.

$# is how many there are, and shift drops the first, failing when there is nothing left to drop.

Try this

$

Files

The files in the sandbox, with their modes, link counts and sizes
ModeLinksSizeName
-rw-r--r--1100agenda.md
-rw-r--r--164notes.txt