How to spread all arguments in a .sh script

This article was published on Sep 18, 2021, and takes less than a minute to read.

After I've learned how to use scripty, having basic .sh is part of my workflow even not being a shell scripting expert.

Since scripty does not pass down the CLI arguments to my scripts:

# Consider building a script
yarn build --scope=mdx-prism-2

I have to do it manually:

lerna build $1

$1 is the first argument I passed in the previous command, in that case, --scope=mdx-prism-2.

But if I need to pass more params like:

yarn build --scope=mdx-prism-2 --scope=@raulfdm/core --scope=@raulmelo/styles

Instead of doing:

lerna build $1 $2 $3

I learned that I could simply spread all arguments with $@:

lerna build $@

And now I no longer have to worry about how many params my script supports because all will be spread!