Is word splitting a part of POSIX?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite
1












I know that Bash has word splitting but zsh doesn't, and I'm not familiar with others(csh, tcsh, ksh, etc), but I was wondering if it is a part of any standard.



In other words, does sh have word splitting, or is it a Bash-only feature? If I wanted to write a portable shell script, would I have to account for word splitting, or is it something nonstandard that is added by other shells?







share|improve this question






















  • zsh has word splitting as well but it's not done implicitly (unless zsh runs in sh/bash/ksh emulation), you have to request it: $=var instead of $var. Same for globbing upon expansions, another thing that is done implicitly by POSIX shells and is about as dangerous/unwanted as word splitting: $~var instead of $var. So $var in POSIX shells is like $=~var in zsh.
    – Stéphane Chazelas
    Jan 23 at 20:12















up vote
3
down vote

favorite
1












I know that Bash has word splitting but zsh doesn't, and I'm not familiar with others(csh, tcsh, ksh, etc), but I was wondering if it is a part of any standard.



In other words, does sh have word splitting, or is it a Bash-only feature? If I wanted to write a portable shell script, would I have to account for word splitting, or is it something nonstandard that is added by other shells?







share|improve this question






















  • zsh has word splitting as well but it's not done implicitly (unless zsh runs in sh/bash/ksh emulation), you have to request it: $=var instead of $var. Same for globbing upon expansions, another thing that is done implicitly by POSIX shells and is about as dangerous/unwanted as word splitting: $~var instead of $var. So $var in POSIX shells is like $=~var in zsh.
    – Stéphane Chazelas
    Jan 23 at 20:12













up vote
3
down vote

favorite
1









up vote
3
down vote

favorite
1






1





I know that Bash has word splitting but zsh doesn't, and I'm not familiar with others(csh, tcsh, ksh, etc), but I was wondering if it is a part of any standard.



In other words, does sh have word splitting, or is it a Bash-only feature? If I wanted to write a portable shell script, would I have to account for word splitting, or is it something nonstandard that is added by other shells?







share|improve this question














I know that Bash has word splitting but zsh doesn't, and I'm not familiar with others(csh, tcsh, ksh, etc), but I was wondering if it is a part of any standard.



In other words, does sh have word splitting, or is it a Bash-only feature? If I wanted to write a portable shell script, would I have to account for word splitting, or is it something nonstandard that is added by other shells?









share|improve this question













share|improve this question




share|improve this question








edited Apr 1 at 8:27









codeforester

336314




336314










asked Jan 23 at 17:54









3p1k5auc3

232




232











  • zsh has word splitting as well but it's not done implicitly (unless zsh runs in sh/bash/ksh emulation), you have to request it: $=var instead of $var. Same for globbing upon expansions, another thing that is done implicitly by POSIX shells and is about as dangerous/unwanted as word splitting: $~var instead of $var. So $var in POSIX shells is like $=~var in zsh.
    – Stéphane Chazelas
    Jan 23 at 20:12

















  • zsh has word splitting as well but it's not done implicitly (unless zsh runs in sh/bash/ksh emulation), you have to request it: $=var instead of $var. Same for globbing upon expansions, another thing that is done implicitly by POSIX shells and is about as dangerous/unwanted as word splitting: $~var instead of $var. So $var in POSIX shells is like $=~var in zsh.
    – Stéphane Chazelas
    Jan 23 at 20:12
















zsh has word splitting as well but it's not done implicitly (unless zsh runs in sh/bash/ksh emulation), you have to request it: $=var instead of $var. Same for globbing upon expansions, another thing that is done implicitly by POSIX shells and is about as dangerous/unwanted as word splitting: $~var instead of $var. So $var in POSIX shells is like $=~var in zsh.
– Stéphane Chazelas
Jan 23 at 20:12





zsh has word splitting as well but it's not done implicitly (unless zsh runs in sh/bash/ksh emulation), you have to request it: $=var instead of $var. Same for globbing upon expansions, another thing that is done implicitly by POSIX shells and is about as dangerous/unwanted as word splitting: $~var instead of $var. So $var in POSIX shells is like $=~var in zsh.
– Stéphane Chazelas
Jan 23 at 20:12











2 Answers
2






active

oldest

votes

















up vote
4
down vote



accepted










Implicit word splitting, i.e. word splitting on an unquoted variable expansion ($foo as opposed to "$foo"), is something that all POSIX compliant shells do, and more generally all sh shells. They also perform globbing on the result. This is why you need double quotes around variable substitutions. The same goes for command substitutions.



POSIX calls these field splitting and pathname expansion.



Zsh deviates from the standard sh behavior. It doesn't perform word splitting on unquoted variable substitutions (but it does perform word splitting on unquoted command substitutions), and it doesn't perform globbing on unquoted substitutions at all. (Zsh has those features, of course, but they're explicit: $=foo to do word splitting and $~foo to do globbing.) Zsh is not an sh-compatible shell; it's fairly close, but not compatible, and the reduced implicit splitting is one of the main deviations. Zsh has a compatibility mode (which is entered automatically if the zsh executable is called sh or ksh) in which it does perform implicit word splitting and globbing like sh, among other things.



Bash and ksh are both sh-compatible shells. Bash does have a few incompatibilities with POSIX, but you have to dig a lot deeper to find them. On important issues like implicit splitting, it's compatible.



(T)csh is a completely different family of shells. Its syntax is vastly different from sh. It's also pretty much dead, so don't worry about it.






share|improve this answer




















  • Thanks for the detailed explanation of all the different shells, this is exactly what I was looking for.
    – 3p1k5auc3
    Jan 24 at 16:33

















up vote
2
down vote













Field splitting is in the POSIX standard: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05




After parameter expansion (Parameter Expansion), command substitution (Command Substitution), and arithmetic expansion (Arithmetic Expansion), the shell shall scan the results of expansions and substitutions that did not occur in double-quotes for field splitting and multiple fields can result.



The shell shall treat each character of the IFS as a delimiter and use the delimiters as field terminators to split the results of parameter expansion, command substitution, and arithmetic expansion into fields.







share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    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',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f419148%2fis-word-splitting-a-part-of-posix%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    4
    down vote



    accepted










    Implicit word splitting, i.e. word splitting on an unquoted variable expansion ($foo as opposed to "$foo"), is something that all POSIX compliant shells do, and more generally all sh shells. They also perform globbing on the result. This is why you need double quotes around variable substitutions. The same goes for command substitutions.



    POSIX calls these field splitting and pathname expansion.



    Zsh deviates from the standard sh behavior. It doesn't perform word splitting on unquoted variable substitutions (but it does perform word splitting on unquoted command substitutions), and it doesn't perform globbing on unquoted substitutions at all. (Zsh has those features, of course, but they're explicit: $=foo to do word splitting and $~foo to do globbing.) Zsh is not an sh-compatible shell; it's fairly close, but not compatible, and the reduced implicit splitting is one of the main deviations. Zsh has a compatibility mode (which is entered automatically if the zsh executable is called sh or ksh) in which it does perform implicit word splitting and globbing like sh, among other things.



    Bash and ksh are both sh-compatible shells. Bash does have a few incompatibilities with POSIX, but you have to dig a lot deeper to find them. On important issues like implicit splitting, it's compatible.



    (T)csh is a completely different family of shells. Its syntax is vastly different from sh. It's also pretty much dead, so don't worry about it.






    share|improve this answer




















    • Thanks for the detailed explanation of all the different shells, this is exactly what I was looking for.
      – 3p1k5auc3
      Jan 24 at 16:33














    up vote
    4
    down vote



    accepted










    Implicit word splitting, i.e. word splitting on an unquoted variable expansion ($foo as opposed to "$foo"), is something that all POSIX compliant shells do, and more generally all sh shells. They also perform globbing on the result. This is why you need double quotes around variable substitutions. The same goes for command substitutions.



    POSIX calls these field splitting and pathname expansion.



    Zsh deviates from the standard sh behavior. It doesn't perform word splitting on unquoted variable substitutions (but it does perform word splitting on unquoted command substitutions), and it doesn't perform globbing on unquoted substitutions at all. (Zsh has those features, of course, but they're explicit: $=foo to do word splitting and $~foo to do globbing.) Zsh is not an sh-compatible shell; it's fairly close, but not compatible, and the reduced implicit splitting is one of the main deviations. Zsh has a compatibility mode (which is entered automatically if the zsh executable is called sh or ksh) in which it does perform implicit word splitting and globbing like sh, among other things.



    Bash and ksh are both sh-compatible shells. Bash does have a few incompatibilities with POSIX, but you have to dig a lot deeper to find them. On important issues like implicit splitting, it's compatible.



    (T)csh is a completely different family of shells. Its syntax is vastly different from sh. It's also pretty much dead, so don't worry about it.






    share|improve this answer




















    • Thanks for the detailed explanation of all the different shells, this is exactly what I was looking for.
      – 3p1k5auc3
      Jan 24 at 16:33












    up vote
    4
    down vote



    accepted







    up vote
    4
    down vote



    accepted






    Implicit word splitting, i.e. word splitting on an unquoted variable expansion ($foo as opposed to "$foo"), is something that all POSIX compliant shells do, and more generally all sh shells. They also perform globbing on the result. This is why you need double quotes around variable substitutions. The same goes for command substitutions.



    POSIX calls these field splitting and pathname expansion.



    Zsh deviates from the standard sh behavior. It doesn't perform word splitting on unquoted variable substitutions (but it does perform word splitting on unquoted command substitutions), and it doesn't perform globbing on unquoted substitutions at all. (Zsh has those features, of course, but they're explicit: $=foo to do word splitting and $~foo to do globbing.) Zsh is not an sh-compatible shell; it's fairly close, but not compatible, and the reduced implicit splitting is one of the main deviations. Zsh has a compatibility mode (which is entered automatically if the zsh executable is called sh or ksh) in which it does perform implicit word splitting and globbing like sh, among other things.



    Bash and ksh are both sh-compatible shells. Bash does have a few incompatibilities with POSIX, but you have to dig a lot deeper to find them. On important issues like implicit splitting, it's compatible.



    (T)csh is a completely different family of shells. Its syntax is vastly different from sh. It's also pretty much dead, so don't worry about it.






    share|improve this answer












    Implicit word splitting, i.e. word splitting on an unquoted variable expansion ($foo as opposed to "$foo"), is something that all POSIX compliant shells do, and more generally all sh shells. They also perform globbing on the result. This is why you need double quotes around variable substitutions. The same goes for command substitutions.



    POSIX calls these field splitting and pathname expansion.



    Zsh deviates from the standard sh behavior. It doesn't perform word splitting on unquoted variable substitutions (but it does perform word splitting on unquoted command substitutions), and it doesn't perform globbing on unquoted substitutions at all. (Zsh has those features, of course, but they're explicit: $=foo to do word splitting and $~foo to do globbing.) Zsh is not an sh-compatible shell; it's fairly close, but not compatible, and the reduced implicit splitting is one of the main deviations. Zsh has a compatibility mode (which is entered automatically if the zsh executable is called sh or ksh) in which it does perform implicit word splitting and globbing like sh, among other things.



    Bash and ksh are both sh-compatible shells. Bash does have a few incompatibilities with POSIX, but you have to dig a lot deeper to find them. On important issues like implicit splitting, it's compatible.



    (T)csh is a completely different family of shells. Its syntax is vastly different from sh. It's also pretty much dead, so don't worry about it.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 23 at 23:20









    Gilles

    506k11910011529




    506k11910011529











    • Thanks for the detailed explanation of all the different shells, this is exactly what I was looking for.
      – 3p1k5auc3
      Jan 24 at 16:33
















    • Thanks for the detailed explanation of all the different shells, this is exactly what I was looking for.
      – 3p1k5auc3
      Jan 24 at 16:33















    Thanks for the detailed explanation of all the different shells, this is exactly what I was looking for.
    – 3p1k5auc3
    Jan 24 at 16:33




    Thanks for the detailed explanation of all the different shells, this is exactly what I was looking for.
    – 3p1k5auc3
    Jan 24 at 16:33












    up vote
    2
    down vote













    Field splitting is in the POSIX standard: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05




    After parameter expansion (Parameter Expansion), command substitution (Command Substitution), and arithmetic expansion (Arithmetic Expansion), the shell shall scan the results of expansions and substitutions that did not occur in double-quotes for field splitting and multiple fields can result.



    The shell shall treat each character of the IFS as a delimiter and use the delimiters as field terminators to split the results of parameter expansion, command substitution, and arithmetic expansion into fields.







    share|improve this answer
























      up vote
      2
      down vote













      Field splitting is in the POSIX standard: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05




      After parameter expansion (Parameter Expansion), command substitution (Command Substitution), and arithmetic expansion (Arithmetic Expansion), the shell shall scan the results of expansions and substitutions that did not occur in double-quotes for field splitting and multiple fields can result.



      The shell shall treat each character of the IFS as a delimiter and use the delimiters as field terminators to split the results of parameter expansion, command substitution, and arithmetic expansion into fields.







      share|improve this answer






















        up vote
        2
        down vote










        up vote
        2
        down vote









        Field splitting is in the POSIX standard: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05




        After parameter expansion (Parameter Expansion), command substitution (Command Substitution), and arithmetic expansion (Arithmetic Expansion), the shell shall scan the results of expansions and substitutions that did not occur in double-quotes for field splitting and multiple fields can result.



        The shell shall treat each character of the IFS as a delimiter and use the delimiters as field terminators to split the results of parameter expansion, command substitution, and arithmetic expansion into fields.







        share|improve this answer












        Field splitting is in the POSIX standard: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05




        After parameter expansion (Parameter Expansion), command substitution (Command Substitution), and arithmetic expansion (Arithmetic Expansion), the shell shall scan the results of expansions and substitutions that did not occur in double-quotes for field splitting and multiple fields can result.



        The shell shall treat each character of the IFS as a delimiter and use the delimiters as field terminators to split the results of parameter expansion, command substitution, and arithmetic expansion into fields.








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 23 at 18:54









        Patrick Mevzek

        2,0131721




        2,0131721






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f419148%2fis-word-splitting-a-part-of-posix%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?