for all txt files
eval mybin "$(printf -- '--conf %q ' *.txt)"
If only for certain txt files
eval mybin '--conf "'{a,b,c}.txt'"'
Maybe we should use a wrapper function. This is not a builtin solution, but it works well than the previous two commands if filenames contain spaces or special characters.
function mybinw
:
function mybinw() {
declare -a mybin_opts
for file in "$@"; do
mybin_opts+=(--conf "$file")
done
mybin "${mybin_opts[@]}"
}
Test:
mybin
:
#!/bin/bash
for q in "$@"; do
echo "=> $q"
done
Create some txt files, some file names include spaces or special characters
touch {a,b,c,d,efg,"h h"}.txt 'a(1).txt' 'b;b.txt'
For all txt files:
eval mybin "$(printf -- '--conf %q ' *.txt)"
=> --conf
=> a(1).txt
=> --conf
=> a.txt
=> --conf
=> b;b.txt
=> --conf
=> b.txt
=> --conf
=> c.txt
=> --conf
=> d.txt
=> --conf
=> efg.txt
=> --conf
=> h h.txt
for certain txt files:
eval mybin '--conf "'{a,b,c,"h h"}.txt'"'
=> --conf
=> a.txt
=> --conf
=> b.txt
=> --conf
=> c.txt
=> --conf
=> h h.txt
Using a wrapper function
touch 'c"c.txt'
mybinw *.txt
=> --conf
=> a(1).txt
=> --conf
=> a"b.txt
=> --conf
=> a.txt
=> --conf
=> b;b.txt
=> --conf
=> b.txt
=> --conf
=> c"c.txt
=> --conf
=> c.txt
=> --conf
=> d.txt
=> --conf
=> efg.txt
=> --conf
=> h h.txt