Reputation: 11226
I realise this question already exists, but the solutions are not actually changing the delimiter. I would like to know if there is anyway to change the delimiter or if anybody knows where it resides.
Say i need to pass this string to a program, delimited by commas as that is what the program accepts
echo \"abc" "{def,ghi}\"
prints
"abc def" "abc ghi"
where i would want
"abc def","abc ghi"
Obviously this is just a simple example though.
Nothing as i have no idea where to look for this delimiter, although i have searched pretty extensively
Also as a sub question:
Using choroba's answer from the other question creates errors when trying to use it to pass it to my script. Admittedly i haven't tried for long though
I tried
./script ( set abc" "{def,ghi} ; IFS=: ; echo "$*" )
./script < <( set abc" "{def,ghi} ; IFS=: ; echo "$*" )
./scipt $(( set abc" "{def,ghi} ; IFS=: ; echo "$*" ))
Upvotes: 5
Views: 3376
Reputation: 15185
So my test script looks like:
#!/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 were missing the $
to invoke the subshell.
Updated for main question (whether there is an option to change the separator):
After looking into bash v4.3 source:
When doing
./my_script.sh \"abc\ {1,2}\"
there is no way of adding any other separator because there is no separator. The command gets two arguments passed to it "abc 1"
and "abc 2"
.
The case of
echo \"abc\ {1,2}\"
You would need to expand the built-in echo to have either an option or global variable to set the words separator. Currently this is done by putchar(' ')
in echo_builtin
in builtins/echo.def:192
Upvotes: 6