Run a command using arguments that come from an array
17
votes
4
answers
17607
views
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.
Asked by Flux
(3238 rep)
Dec 23, 2017, 08:25 AM
Last activity: Feb 23, 2024, 08:42 AM
Last activity: Feb 23, 2024, 08:42 AM