Change delimiter / delimiter in bash brace expansion
Premise
I understand the question already exists, but the solutions don't actually change the delimiter. I would like to know if there is a way to change the delimiter or if anyone knows where it is.
Example
Let's say I need to pass this string to a comma separated program since the program takes
echo \"abc" "{def,ghi}\"
prints
"abc def" "abc ghi"
where would i like
"abc def","abc ghi"
Obviously this is a simple example.
What i tried
Nothing, as I have no idea where to look for this separator, although I searched quite extensively
Also as an additional question:
Using the choroba answer from another question creates errors when I try to use it to pipe it to my script. Admittedly I haven't tried it for a long time though
I tried
./script ( set abc" "{def,ghi} ; IFS=: ; echo "$*" )
./script < <( set abc" "{def,ghi} ; IFS=: ; echo "$*" )
./scipt $(( set abc" "{def,ghi} ; IFS=: ; echo "$*" ))
source to share
So my test script looks like this:
#!/usr/bin/env bash
echo "$@"
And it works fine with:
./my_script.sh $(set \"abc\ {def,ghi}\"; IFS=,; echo "$*")
It outputs:
"abc def","abc ghi"
I guess you are missing enough $
to call the subshell.
Updated for the main question (is there an option to change the delimiter):
After looking at the source of bash v4.3:
By doing
./my_script.sh \"abc\ {1,2}\"
there is no way to add any other delimiter because there is no delimiter. The command receives two arguments passed to it "abc 1"
and "abc 2"
.
Happening
echo \"abc\ {1,2}\"
You will need to extend the inline echo so that either the parameter or the global variable sets the word separator. Currently, this is done putchar(' ')
in echo_builtin
inbuiltins/echo.def:192
source to share