In Bash, we can use $@
to quickly pass all arguments we received in one script to another script or program. For example, let's say we have the following code:
#!/usr/bin/env bash
echo You passed me: $@
If we save this as script.sh
, make it executable, and run it like this:
chmod +x ./script.sh
./script.sh first second third fourth
This is what we'll get as output:
You passed me: first second third fourth
Observe that the zeroth argument ($0
: the program's name) isn't passed when we use $@
.
Leave a Reply