How to get an alternate separator for brace expansion?2019 Community Moderator ElectionGet the source directory of a Bash script from within the script itselfHow do I parse command line arguments in Bash?How to check if a string contains a substring in BashHow to check if a program exists from a Bash script?How do I tell if a regular file does not exist in Bash?How do I split a string on a delimiter in Bash?How to count all the lines of code in a directory recursively?How to use double or single brackets, parentheses, curly bracesHow do I reload .bashrc without logging out and back in?How to concatenate string variables in Bash

How to read string as hex number in bash?

Is "inadequate referencing" a euphemism for plagiarism?

How are passwords stolen from companies if they only store hashes?

Print last inputted byte

How do you justify more code being written by following clean code practices?

Hot air balloons as primitive bombers

Imaginary part of expression too difficult to calculate

How old is Nick Fury?

When should a starting writer get his own webpage?

"Marked down as someone wanting to sell shares." What does that mean?

The English Debate

How can an organ that provides biological immortality be unable to regenerate?

Would this string work as string?

Nested Dynamic SOQL Query

Air travel with refrigerated insulin

Hackerrank All Women's Codesprint 2019: Name the Product

Pre-Employment Background Check With Consent For Future Checks

Why doesn't the fusion process of the sun speed up?

Weird lines in Microsoft Word

Can "few" be used as a subject? If so, what is the rule?

Help with identifying unique aircraft over NE Pennsylvania

PTIJ: Which Dr. Seuss books should one obtain?

What are the rules for concealing thieves' tools (or items in general)?

What kind of footwear is suitable for walking in micro gravity environment?



How to get an alternate separator for brace expansion?



2019 Community Moderator ElectionGet the source directory of a Bash script from within the script itselfHow do I parse command line arguments in Bash?How to check if a string contains a substring in BashHow to check if a program exists from a Bash script?How do I tell if a regular file does not exist in Bash?How do I split a string on a delimiter in Bash?How to count all the lines of code in a directory recursively?How to use double or single brackets, parentheses, curly bracesHow do I reload .bashrc without logging out and back in?How to concatenate string variables in Bash










2















I find myself often doing silly things like:



cmd $( echo foo1,2,3 | tr ' ' , )


when I want to invoke cmd foo1,foo2,foo3. I would like instead to be able to do something along the lines of:



OFS=, ; cmd foo1,2,3



to force the brace expansion to give me a comma separated list. Is there any such functionality available?










share|improve this question






















  • If cmd is always the same, a function might help.

    – Cyrus
    Mar 7 at 18:51











  • Interestingly, the documentation for neither brace expansion nor pathname expansion (to which brace expansion is compared) ever actually says what the result is. It just says a "list" of words.

    – chepner
    Mar 7 at 18:52












  • The closest thing I know of would be a clumsy use of an array. cmd "$(IFS=,; x=(foo1,2,3); printf '%s' "$x[*]")".

    – chepner
    Mar 7 at 18:55
















2















I find myself often doing silly things like:



cmd $( echo foo1,2,3 | tr ' ' , )


when I want to invoke cmd foo1,foo2,foo3. I would like instead to be able to do something along the lines of:



OFS=, ; cmd foo1,2,3



to force the brace expansion to give me a comma separated list. Is there any such functionality available?










share|improve this question






















  • If cmd is always the same, a function might help.

    – Cyrus
    Mar 7 at 18:51











  • Interestingly, the documentation for neither brace expansion nor pathname expansion (to which brace expansion is compared) ever actually says what the result is. It just says a "list" of words.

    – chepner
    Mar 7 at 18:52












  • The closest thing I know of would be a clumsy use of an array. cmd "$(IFS=,; x=(foo1,2,3); printf '%s' "$x[*]")".

    – chepner
    Mar 7 at 18:55














2












2








2


1






I find myself often doing silly things like:



cmd $( echo foo1,2,3 | tr ' ' , )


when I want to invoke cmd foo1,foo2,foo3. I would like instead to be able to do something along the lines of:



OFS=, ; cmd foo1,2,3



to force the brace expansion to give me a comma separated list. Is there any such functionality available?










share|improve this question














I find myself often doing silly things like:



cmd $( echo foo1,2,3 | tr ' ' , )


when I want to invoke cmd foo1,foo2,foo3. I would like instead to be able to do something along the lines of:



OFS=, ; cmd foo1,2,3



to force the brace expansion to give me a comma separated list. Is there any such functionality available?







bash






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 7 at 18:43









William PursellWilliam Pursell

133k32206240




133k32206240












  • If cmd is always the same, a function might help.

    – Cyrus
    Mar 7 at 18:51











  • Interestingly, the documentation for neither brace expansion nor pathname expansion (to which brace expansion is compared) ever actually says what the result is. It just says a "list" of words.

    – chepner
    Mar 7 at 18:52












  • The closest thing I know of would be a clumsy use of an array. cmd "$(IFS=,; x=(foo1,2,3); printf '%s' "$x[*]")".

    – chepner
    Mar 7 at 18:55


















  • If cmd is always the same, a function might help.

    – Cyrus
    Mar 7 at 18:51











  • Interestingly, the documentation for neither brace expansion nor pathname expansion (to which brace expansion is compared) ever actually says what the result is. It just says a "list" of words.

    – chepner
    Mar 7 at 18:52












  • The closest thing I know of would be a clumsy use of an array. cmd "$(IFS=,; x=(foo1,2,3); printf '%s' "$x[*]")".

    – chepner
    Mar 7 at 18:55

















If cmd is always the same, a function might help.

– Cyrus
Mar 7 at 18:51





If cmd is always the same, a function might help.

– Cyrus
Mar 7 at 18:51













Interestingly, the documentation for neither brace expansion nor pathname expansion (to which brace expansion is compared) ever actually says what the result is. It just says a "list" of words.

– chepner
Mar 7 at 18:52






Interestingly, the documentation for neither brace expansion nor pathname expansion (to which brace expansion is compared) ever actually says what the result is. It just says a "list" of words.

– chepner
Mar 7 at 18:52














The closest thing I know of would be a clumsy use of an array. cmd "$(IFS=,; x=(foo1,2,3); printf '%s' "$x[*]")".

– chepner
Mar 7 at 18:55






The closest thing I know of would be a clumsy use of an array. cmd "$(IFS=,; x=(foo1,2,3); printf '%s' "$x[*]")".

– chepner
Mar 7 at 18:55













2 Answers
2






active

oldest

votes


















4














I don't think it's possible with a simple variable or setting.



However, you can capture the brace expansion in an array, and then use IFS and parameter substitution to achieve that effect:



$ ( a=( foo1,2,3 ); IFS=,; printf -- "%sn" "$a[*]" )
foo1,foo2,foo3


There, I'm using a subshell so I don't alter IFS in the current shell.




Here's a short
function that's much tidier:



$ join() local IFS=$1; shift; printf -- "%sn" "$*"; 
$ join , foo1,2,3
foo1,foo2,foo3





share|improve this answer






























    4














    You can create a function that will echo a comma-separated list of its args:



    commas() local IFS=,; echo "$*"; 


    Then you can use it in your calls to cmd:



    cmd "$(commas foo1,2,3)"


    Edit: Note that echo is somewhat broken, in that if you pass a single arg that looks like a valid echo options (e.g., -e, -n, etc), echo will consume it and interpret it as an option instead of printing it.



    $ commas -e #prints nothing
    $ commas -n #prints nothing
    $ commas -e -n
    -e,-n


    The last one works because "$*" expands to -e,-n, which echo sees as a single argument.



    And echo doesn't respect the -- argument as an "end of options" indicator like printf does. So you may want to use printf -- "%sn" "$*", as in @glennjackman's answer. Then again, the whole point of the commas function is to combine multiple args into a comma-separated list, as a single string. So it's probably unlikely that you'd run into any issues with echo. But hey, it only costs you a few more characters to type printf -- "%s" instead of echo.






    share|improve this answer

























    • The unquoted command substitution can cause problems, depending on what the arguments to commas end up being.

      – chepner
      Mar 7 at 18:59











    • @Aaron Fixed. Thanks.

      – Mike Holt
      Mar 7 at 18:59











    • @chepner Well spotted. Thanks.

      – Mike Holt
      Mar 7 at 19:00










    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050760%2fhow-to-get-an-alternate-separator-for-brace-expansion%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4














    I don't think it's possible with a simple variable or setting.



    However, you can capture the brace expansion in an array, and then use IFS and parameter substitution to achieve that effect:



    $ ( a=( foo1,2,3 ); IFS=,; printf -- "%sn" "$a[*]" )
    foo1,foo2,foo3


    There, I'm using a subshell so I don't alter IFS in the current shell.




    Here's a short
    function that's much tidier:



    $ join() local IFS=$1; shift; printf -- "%sn" "$*"; 
    $ join , foo1,2,3
    foo1,foo2,foo3





    share|improve this answer



























      4














      I don't think it's possible with a simple variable or setting.



      However, you can capture the brace expansion in an array, and then use IFS and parameter substitution to achieve that effect:



      $ ( a=( foo1,2,3 ); IFS=,; printf -- "%sn" "$a[*]" )
      foo1,foo2,foo3


      There, I'm using a subshell so I don't alter IFS in the current shell.




      Here's a short
      function that's much tidier:



      $ join() local IFS=$1; shift; printf -- "%sn" "$*"; 
      $ join , foo1,2,3
      foo1,foo2,foo3





      share|improve this answer

























        4












        4








        4







        I don't think it's possible with a simple variable or setting.



        However, you can capture the brace expansion in an array, and then use IFS and parameter substitution to achieve that effect:



        $ ( a=( foo1,2,3 ); IFS=,; printf -- "%sn" "$a[*]" )
        foo1,foo2,foo3


        There, I'm using a subshell so I don't alter IFS in the current shell.




        Here's a short
        function that's much tidier:



        $ join() local IFS=$1; shift; printf -- "%sn" "$*"; 
        $ join , foo1,2,3
        foo1,foo2,foo3





        share|improve this answer













        I don't think it's possible with a simple variable or setting.



        However, you can capture the brace expansion in an array, and then use IFS and parameter substitution to achieve that effect:



        $ ( a=( foo1,2,3 ); IFS=,; printf -- "%sn" "$a[*]" )
        foo1,foo2,foo3


        There, I'm using a subshell so I don't alter IFS in the current shell.




        Here's a short
        function that's much tidier:



        $ join() local IFS=$1; shift; printf -- "%sn" "$*"; 
        $ join , foo1,2,3
        foo1,foo2,foo3






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 7 at 18:55









        glenn jackmanglenn jackman

        170k26147240




        170k26147240























            4














            You can create a function that will echo a comma-separated list of its args:



            commas() local IFS=,; echo "$*"; 


            Then you can use it in your calls to cmd:



            cmd "$(commas foo1,2,3)"


            Edit: Note that echo is somewhat broken, in that if you pass a single arg that looks like a valid echo options (e.g., -e, -n, etc), echo will consume it and interpret it as an option instead of printing it.



            $ commas -e #prints nothing
            $ commas -n #prints nothing
            $ commas -e -n
            -e,-n


            The last one works because "$*" expands to -e,-n, which echo sees as a single argument.



            And echo doesn't respect the -- argument as an "end of options" indicator like printf does. So you may want to use printf -- "%sn" "$*", as in @glennjackman's answer. Then again, the whole point of the commas function is to combine multiple args into a comma-separated list, as a single string. So it's probably unlikely that you'd run into any issues with echo. But hey, it only costs you a few more characters to type printf -- "%s" instead of echo.






            share|improve this answer

























            • The unquoted command substitution can cause problems, depending on what the arguments to commas end up being.

              – chepner
              Mar 7 at 18:59











            • @Aaron Fixed. Thanks.

              – Mike Holt
              Mar 7 at 18:59











            • @chepner Well spotted. Thanks.

              – Mike Holt
              Mar 7 at 19:00















            4














            You can create a function that will echo a comma-separated list of its args:



            commas() local IFS=,; echo "$*"; 


            Then you can use it in your calls to cmd:



            cmd "$(commas foo1,2,3)"


            Edit: Note that echo is somewhat broken, in that if you pass a single arg that looks like a valid echo options (e.g., -e, -n, etc), echo will consume it and interpret it as an option instead of printing it.



            $ commas -e #prints nothing
            $ commas -n #prints nothing
            $ commas -e -n
            -e,-n


            The last one works because "$*" expands to -e,-n, which echo sees as a single argument.



            And echo doesn't respect the -- argument as an "end of options" indicator like printf does. So you may want to use printf -- "%sn" "$*", as in @glennjackman's answer. Then again, the whole point of the commas function is to combine multiple args into a comma-separated list, as a single string. So it's probably unlikely that you'd run into any issues with echo. But hey, it only costs you a few more characters to type printf -- "%s" instead of echo.






            share|improve this answer

























            • The unquoted command substitution can cause problems, depending on what the arguments to commas end up being.

              – chepner
              Mar 7 at 18:59











            • @Aaron Fixed. Thanks.

              – Mike Holt
              Mar 7 at 18:59











            • @chepner Well spotted. Thanks.

              – Mike Holt
              Mar 7 at 19:00













            4












            4








            4







            You can create a function that will echo a comma-separated list of its args:



            commas() local IFS=,; echo "$*"; 


            Then you can use it in your calls to cmd:



            cmd "$(commas foo1,2,3)"


            Edit: Note that echo is somewhat broken, in that if you pass a single arg that looks like a valid echo options (e.g., -e, -n, etc), echo will consume it and interpret it as an option instead of printing it.



            $ commas -e #prints nothing
            $ commas -n #prints nothing
            $ commas -e -n
            -e,-n


            The last one works because "$*" expands to -e,-n, which echo sees as a single argument.



            And echo doesn't respect the -- argument as an "end of options" indicator like printf does. So you may want to use printf -- "%sn" "$*", as in @glennjackman's answer. Then again, the whole point of the commas function is to combine multiple args into a comma-separated list, as a single string. So it's probably unlikely that you'd run into any issues with echo. But hey, it only costs you a few more characters to type printf -- "%s" instead of echo.






            share|improve this answer















            You can create a function that will echo a comma-separated list of its args:



            commas() local IFS=,; echo "$*"; 


            Then you can use it in your calls to cmd:



            cmd "$(commas foo1,2,3)"


            Edit: Note that echo is somewhat broken, in that if you pass a single arg that looks like a valid echo options (e.g., -e, -n, etc), echo will consume it and interpret it as an option instead of printing it.



            $ commas -e #prints nothing
            $ commas -n #prints nothing
            $ commas -e -n
            -e,-n


            The last one works because "$*" expands to -e,-n, which echo sees as a single argument.



            And echo doesn't respect the -- argument as an "end of options" indicator like printf does. So you may want to use printf -- "%sn" "$*", as in @glennjackman's answer. Then again, the whole point of the commas function is to combine multiple args into a comma-separated list, as a single string. So it's probably unlikely that you'd run into any issues with echo. But hey, it only costs you a few more characters to type printf -- "%s" instead of echo.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 7 at 19:23

























            answered Mar 7 at 18:56









            Mike HoltMike Holt

            2,9021920




            2,9021920












            • The unquoted command substitution can cause problems, depending on what the arguments to commas end up being.

              – chepner
              Mar 7 at 18:59











            • @Aaron Fixed. Thanks.

              – Mike Holt
              Mar 7 at 18:59











            • @chepner Well spotted. Thanks.

              – Mike Holt
              Mar 7 at 19:00

















            • The unquoted command substitution can cause problems, depending on what the arguments to commas end up being.

              – chepner
              Mar 7 at 18:59











            • @Aaron Fixed. Thanks.

              – Mike Holt
              Mar 7 at 18:59











            • @chepner Well spotted. Thanks.

              – Mike Holt
              Mar 7 at 19:00
















            The unquoted command substitution can cause problems, depending on what the arguments to commas end up being.

            – chepner
            Mar 7 at 18:59





            The unquoted command substitution can cause problems, depending on what the arguments to commas end up being.

            – chepner
            Mar 7 at 18:59













            @Aaron Fixed. Thanks.

            – Mike Holt
            Mar 7 at 18:59





            @Aaron Fixed. Thanks.

            – Mike Holt
            Mar 7 at 18:59













            @chepner Well spotted. Thanks.

            – Mike Holt
            Mar 7 at 19:00





            @chepner Well spotted. Thanks.

            – Mike Holt
            Mar 7 at 19:00

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050760%2fhow-to-get-an-alternate-separator-for-brace-expansion%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

            Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

            2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived