Read more

Linux: Refer to all arguments of a script call

Arne Hartherz
July 01, 2011Software engineer at makandra GmbH

In shell scripts you can use $1 to refer to the first argument, $2 for the second, etc. If you want to refer to all arguments (e.g. when writing a bash script that takes an arbitrary amount of arguments and passes them on to another call), you may not want to do a “$1 $2 $3 $4 ...”.

Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

Use $@ instead, like in this script:
$ cat welcome
#!/bin/bash
echo Hello to $@

When called, the above would produce this:
$ ./welcome the world and universe
Hello to the world and universe

Note that $@ works for both sh and bash.

Posted by Arne Hartherz to makandra dev (2011-07-01 15:28)