Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash send string argument as multiple arguments

Tags:

bash

So I have a bash script that is generating a string of commands that I want to be run. The output looks something like

$ program "command1 command2 ... commandN"

But the program is interpreting (as it should) "command1 command2 ... commandN" as one argument.

Is there away to turn pass the string into the argument as split arguments so the program would interpret each command as an individual argument?

$ program command1 command2 ... commandN

Thanks for any help.

like image 275
trev9065 Avatar asked May 05 '15 19:05

trev9065


1 Answers

I've done this, implementing your scenario : The idea is to use "a b c" as argument for cat

$ echo a > a
$ echo b > b
$ echo c > c
$ args="a b c"

Trying "a b c" as "one argument"

$ cat $args
cat: a b c: No such file or directory

Workaround to separate arguments :

$ cat $(echo $args)
a
b
c

Hope it helps you

(So you should run program $(echo "command1 command2 ... commandN")

like image 148
Blusky Avatar answered Sep 29 '22 08:09

Blusky