Bash tip: expand args

Post by Nico Brailovsky @ 2024-02-25 | Permalink | Leave a comment

If you're writing a script and it looks like this

your_bin --arg1 \
         --arg2=123 \
         --arg3=345 \
         --arg4...

It can get pretty ugly to maintain. Instead, try this:

many_args=(
  --arg1
  --arg2=123
  --arg3=345
  --arg4...
)
your_bin "${many_args[@]}"