all!
I need to read arguments from a file ‘data’ that consists of strings like:
-a -camb="1 0.5 1",diff="1 0 0" -q=5
-a -camb="0 1 0" -p -q -f=10
...
Next, that arguments must be passed to a program ./test within a script:
#!/bin/bash
while read line
do
./test "$line"
done < "./data"
the problem is that “$line” is passed as argv[1] to ./test, and not as a sequence of argv[1], argv[2], argv[3]
How can I split the string line to several arguments? I.e. the ./test must takes argv[1], argv[2], and so?
Note, that -camb=”1 0.5 1″,diff=”1 0 0″ must be as whole argument, argv[2]!
You can use eval for this:
There’s a big warning here, however: eval may do more interpretation of the file contents than you want. For example, if it contains any I/O redirects (e.g.
>somefile), they will be applied. Similarly,$variablewill be substituted,; somecommandwill be executed as a separate command, etc. Basically, if the contents of the data file aren’t clean enough, you can get some unexpected and potentially dangerous results.