Suppose I have a graphical program named app
. Usage example: app -t 'first tab' -t 'second tab'
opens two 'tabs' in that program.
The question is: how can I execute the command (i.e. app
) from within a bash
script if the number of arguments can vary?
Consider this:
#!/bin/bash
tabs=(
'first tab'
'second tab'
)
# Open the app (starting with some tabs).
app # ... How to get `app -t 'first tab' -t 'second tab'`?
I would like the above script to have an effect equivalent to app -t 'first tab' -t 'second tab'
. How can such a bash script be written?
Edit: note that the question is asking about composing command line arguments on the fly using an array of arguments.
"${args[@]}"
expands each element of the array to a separate word/argument, so the above works likeapp -t "first tab" -t "second tab"
. If there's some corner case where it fails, please do tell. – ilkkachu Oct 24 '19 at 20:54