Difference between ' and ` on the linux terminal (zsh shell)












0















Using ' and ` leads to different results when setting a variable on the zsh shell script -



>>>one=`echo test`
>>>$one
>>>
>>>two='echo test'
>>>$two
>>>zsh: command not found: echo test


What the are the functions of the two?










share|improve this question


















  • 1





    backticks are used (not POSIX) to run commands.

    – Tico
    Nov 23 '18 at 22:12











  • Here's zsh documentation: quotes, backticks. Also see One post with multiple questions or multiple posts? for why it's better to ask a single question per post.

    – that other guy
    Nov 24 '18 at 2:55








  • 1





    @Tico see POSIX Shell 2.6.3 Command Substitution

    – David C. Rankin
    Nov 24 '18 at 8:58
















0















Using ' and ` leads to different results when setting a variable on the zsh shell script -



>>>one=`echo test`
>>>$one
>>>
>>>two='echo test'
>>>$two
>>>zsh: command not found: echo test


What the are the functions of the two?










share|improve this question


















  • 1





    backticks are used (not POSIX) to run commands.

    – Tico
    Nov 23 '18 at 22:12











  • Here's zsh documentation: quotes, backticks. Also see One post with multiple questions or multiple posts? for why it's better to ask a single question per post.

    – that other guy
    Nov 24 '18 at 2:55








  • 1





    @Tico see POSIX Shell 2.6.3 Command Substitution

    – David C. Rankin
    Nov 24 '18 at 8:58














0












0








0








Using ' and ` leads to different results when setting a variable on the zsh shell script -



>>>one=`echo test`
>>>$one
>>>
>>>two='echo test'
>>>$two
>>>zsh: command not found: echo test


What the are the functions of the two?










share|improve this question














Using ' and ` leads to different results when setting a variable on the zsh shell script -



>>>one=`echo test`
>>>$one
>>>
>>>two='echo test'
>>>$two
>>>zsh: command not found: echo test


What the are the functions of the two?







shell zsh






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 22:08









MonsieurBeiltoMonsieurBeilto

406314




406314








  • 1





    backticks are used (not POSIX) to run commands.

    – Tico
    Nov 23 '18 at 22:12











  • Here's zsh documentation: quotes, backticks. Also see One post with multiple questions or multiple posts? for why it's better to ask a single question per post.

    – that other guy
    Nov 24 '18 at 2:55








  • 1





    @Tico see POSIX Shell 2.6.3 Command Substitution

    – David C. Rankin
    Nov 24 '18 at 8:58














  • 1





    backticks are used (not POSIX) to run commands.

    – Tico
    Nov 23 '18 at 22:12











  • Here's zsh documentation: quotes, backticks. Also see One post with multiple questions or multiple posts? for why it's better to ask a single question per post.

    – that other guy
    Nov 24 '18 at 2:55








  • 1





    @Tico see POSIX Shell 2.6.3 Command Substitution

    – David C. Rankin
    Nov 24 '18 at 8:58








1




1





backticks are used (not POSIX) to run commands.

– Tico
Nov 23 '18 at 22:12





backticks are used (not POSIX) to run commands.

– Tico
Nov 23 '18 at 22:12













Here's zsh documentation: quotes, backticks. Also see One post with multiple questions or multiple posts? for why it's better to ask a single question per post.

– that other guy
Nov 24 '18 at 2:55







Here's zsh documentation: quotes, backticks. Also see One post with multiple questions or multiple posts? for why it's better to ask a single question per post.

– that other guy
Nov 24 '18 at 2:55






1




1





@Tico see POSIX Shell 2.6.3 Command Substitution

– David C. Rankin
Nov 24 '18 at 8:58





@Tico see POSIX Shell 2.6.3 Command Substitution

– David C. Rankin
Nov 24 '18 at 8:58












1 Answer
1






active

oldest

votes


















1














This is not as simple as it may seem. Here is a shallow explanation of what is happening. Depending on the shell (and version), variables such as IFS and other possibilities including at least aliases, any or all of the below may not apply, but I think it's a reasonable way of thinking about it in the normal case. Since I'm more familiar with Bash than Zsh I've included Bash references, but all this should apply to Zsh and other POSIX-ish shells as well.



Let's deconstruct these line by line.



one=`echo test`:




  1. Since the line starts with a valid variable name followed by an equals sign, it is a variable assignment, so the right side is processed first.


  2. `echo test` is a command substitution. (In modern shells this form is discouraged in favour of $(echo test).) This is processed as follows:


    1. The string inside the backticks (echo test) is word split into “echo” and “test”.

    2. The command consisting of the command “echo” is executed with an argument list consisting of a single item “test”. This is a rabbit hole, and I don't know the details, so I won't even try to explain what happens to actually execute this command. I think it has to do with execve?


      1. Standard error (in this case nothing) of the command is sent to the terminal as usual.

      2. Standard output of the command (in this case and this order, the bytes corresponding to the Basic Latin characters “t”, “e”, “s”, “t” and a newline) are then right trimmed of newlines, ending up with the bytes 0x74, 0x65, 0x73 and 0x74.





  3. The bytes above are assigned to the variable one.


$one:




  1. This is a variable substitution. The bytes above are substituted for the variable, and the resulting string is treated as a command.


  2. test is indeed a command (and very likely a zsh built-in as well), so it runs fine and returns with an exit code of 1 because there were no arguments. See help test or man test for an in-depth explanation.


two='echo test':




  1. Same as the other assignment, except the right side is a single quoted string. This means the entire contents between the two apostrophes is considered as a single literal string, and no word splitting occurs in it.

  2. The resulting set of bytes corresponding to the string “echo test” is assigned to the variable two.


$two:




  1. Like the other variable expansion, the entire string is treated as a command, because no word splitting happens before executing it. It would indeed be possible to create a command “echo test” (for example using ln -s /bin/echo '/bin/echo test')

  2. Since the command does not exist on your system (and indeed, on any other sane *nix system), zsh helpfully prints an error message to this effect.






share|improve this answer























    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%2f53453400%2fdifference-between-and-on-the-linux-terminal-zsh-shell%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    This is not as simple as it may seem. Here is a shallow explanation of what is happening. Depending on the shell (and version), variables such as IFS and other possibilities including at least aliases, any or all of the below may not apply, but I think it's a reasonable way of thinking about it in the normal case. Since I'm more familiar with Bash than Zsh I've included Bash references, but all this should apply to Zsh and other POSIX-ish shells as well.



    Let's deconstruct these line by line.



    one=`echo test`:




    1. Since the line starts with a valid variable name followed by an equals sign, it is a variable assignment, so the right side is processed first.


    2. `echo test` is a command substitution. (In modern shells this form is discouraged in favour of $(echo test).) This is processed as follows:


      1. The string inside the backticks (echo test) is word split into “echo” and “test”.

      2. The command consisting of the command “echo” is executed with an argument list consisting of a single item “test”. This is a rabbit hole, and I don't know the details, so I won't even try to explain what happens to actually execute this command. I think it has to do with execve?


        1. Standard error (in this case nothing) of the command is sent to the terminal as usual.

        2. Standard output of the command (in this case and this order, the bytes corresponding to the Basic Latin characters “t”, “e”, “s”, “t” and a newline) are then right trimmed of newlines, ending up with the bytes 0x74, 0x65, 0x73 and 0x74.





    3. The bytes above are assigned to the variable one.


    $one:




    1. This is a variable substitution. The bytes above are substituted for the variable, and the resulting string is treated as a command.


    2. test is indeed a command (and very likely a zsh built-in as well), so it runs fine and returns with an exit code of 1 because there were no arguments. See help test or man test for an in-depth explanation.


    two='echo test':




    1. Same as the other assignment, except the right side is a single quoted string. This means the entire contents between the two apostrophes is considered as a single literal string, and no word splitting occurs in it.

    2. The resulting set of bytes corresponding to the string “echo test” is assigned to the variable two.


    $two:




    1. Like the other variable expansion, the entire string is treated as a command, because no word splitting happens before executing it. It would indeed be possible to create a command “echo test” (for example using ln -s /bin/echo '/bin/echo test')

    2. Since the command does not exist on your system (and indeed, on any other sane *nix system), zsh helpfully prints an error message to this effect.






    share|improve this answer




























      1














      This is not as simple as it may seem. Here is a shallow explanation of what is happening. Depending on the shell (and version), variables such as IFS and other possibilities including at least aliases, any or all of the below may not apply, but I think it's a reasonable way of thinking about it in the normal case. Since I'm more familiar with Bash than Zsh I've included Bash references, but all this should apply to Zsh and other POSIX-ish shells as well.



      Let's deconstruct these line by line.



      one=`echo test`:




      1. Since the line starts with a valid variable name followed by an equals sign, it is a variable assignment, so the right side is processed first.


      2. `echo test` is a command substitution. (In modern shells this form is discouraged in favour of $(echo test).) This is processed as follows:


        1. The string inside the backticks (echo test) is word split into “echo” and “test”.

        2. The command consisting of the command “echo” is executed with an argument list consisting of a single item “test”. This is a rabbit hole, and I don't know the details, so I won't even try to explain what happens to actually execute this command. I think it has to do with execve?


          1. Standard error (in this case nothing) of the command is sent to the terminal as usual.

          2. Standard output of the command (in this case and this order, the bytes corresponding to the Basic Latin characters “t”, “e”, “s”, “t” and a newline) are then right trimmed of newlines, ending up with the bytes 0x74, 0x65, 0x73 and 0x74.





      3. The bytes above are assigned to the variable one.


      $one:




      1. This is a variable substitution. The bytes above are substituted for the variable, and the resulting string is treated as a command.


      2. test is indeed a command (and very likely a zsh built-in as well), so it runs fine and returns with an exit code of 1 because there were no arguments. See help test or man test for an in-depth explanation.


      two='echo test':




      1. Same as the other assignment, except the right side is a single quoted string. This means the entire contents between the two apostrophes is considered as a single literal string, and no word splitting occurs in it.

      2. The resulting set of bytes corresponding to the string “echo test” is assigned to the variable two.


      $two:




      1. Like the other variable expansion, the entire string is treated as a command, because no word splitting happens before executing it. It would indeed be possible to create a command “echo test” (for example using ln -s /bin/echo '/bin/echo test')

      2. Since the command does not exist on your system (and indeed, on any other sane *nix system), zsh helpfully prints an error message to this effect.






      share|improve this answer


























        1












        1








        1







        This is not as simple as it may seem. Here is a shallow explanation of what is happening. Depending on the shell (and version), variables such as IFS and other possibilities including at least aliases, any or all of the below may not apply, but I think it's a reasonable way of thinking about it in the normal case. Since I'm more familiar with Bash than Zsh I've included Bash references, but all this should apply to Zsh and other POSIX-ish shells as well.



        Let's deconstruct these line by line.



        one=`echo test`:




        1. Since the line starts with a valid variable name followed by an equals sign, it is a variable assignment, so the right side is processed first.


        2. `echo test` is a command substitution. (In modern shells this form is discouraged in favour of $(echo test).) This is processed as follows:


          1. The string inside the backticks (echo test) is word split into “echo” and “test”.

          2. The command consisting of the command “echo” is executed with an argument list consisting of a single item “test”. This is a rabbit hole, and I don't know the details, so I won't even try to explain what happens to actually execute this command. I think it has to do with execve?


            1. Standard error (in this case nothing) of the command is sent to the terminal as usual.

            2. Standard output of the command (in this case and this order, the bytes corresponding to the Basic Latin characters “t”, “e”, “s”, “t” and a newline) are then right trimmed of newlines, ending up with the bytes 0x74, 0x65, 0x73 and 0x74.





        3. The bytes above are assigned to the variable one.


        $one:




        1. This is a variable substitution. The bytes above are substituted for the variable, and the resulting string is treated as a command.


        2. test is indeed a command (and very likely a zsh built-in as well), so it runs fine and returns with an exit code of 1 because there were no arguments. See help test or man test for an in-depth explanation.


        two='echo test':




        1. Same as the other assignment, except the right side is a single quoted string. This means the entire contents between the two apostrophes is considered as a single literal string, and no word splitting occurs in it.

        2. The resulting set of bytes corresponding to the string “echo test” is assigned to the variable two.


        $two:




        1. Like the other variable expansion, the entire string is treated as a command, because no word splitting happens before executing it. It would indeed be possible to create a command “echo test” (for example using ln -s /bin/echo '/bin/echo test')

        2. Since the command does not exist on your system (and indeed, on any other sane *nix system), zsh helpfully prints an error message to this effect.






        share|improve this answer













        This is not as simple as it may seem. Here is a shallow explanation of what is happening. Depending on the shell (and version), variables such as IFS and other possibilities including at least aliases, any or all of the below may not apply, but I think it's a reasonable way of thinking about it in the normal case. Since I'm more familiar with Bash than Zsh I've included Bash references, but all this should apply to Zsh and other POSIX-ish shells as well.



        Let's deconstruct these line by line.



        one=`echo test`:




        1. Since the line starts with a valid variable name followed by an equals sign, it is a variable assignment, so the right side is processed first.


        2. `echo test` is a command substitution. (In modern shells this form is discouraged in favour of $(echo test).) This is processed as follows:


          1. The string inside the backticks (echo test) is word split into “echo” and “test”.

          2. The command consisting of the command “echo” is executed with an argument list consisting of a single item “test”. This is a rabbit hole, and I don't know the details, so I won't even try to explain what happens to actually execute this command. I think it has to do with execve?


            1. Standard error (in this case nothing) of the command is sent to the terminal as usual.

            2. Standard output of the command (in this case and this order, the bytes corresponding to the Basic Latin characters “t”, “e”, “s”, “t” and a newline) are then right trimmed of newlines, ending up with the bytes 0x74, 0x65, 0x73 and 0x74.





        3. The bytes above are assigned to the variable one.


        $one:




        1. This is a variable substitution. The bytes above are substituted for the variable, and the resulting string is treated as a command.


        2. test is indeed a command (and very likely a zsh built-in as well), so it runs fine and returns with an exit code of 1 because there were no arguments. See help test or man test for an in-depth explanation.


        two='echo test':




        1. Same as the other assignment, except the right side is a single quoted string. This means the entire contents between the two apostrophes is considered as a single literal string, and no word splitting occurs in it.

        2. The resulting set of bytes corresponding to the string “echo test” is assigned to the variable two.


        $two:




        1. Like the other variable expansion, the entire string is treated as a command, because no word splitting happens before executing it. It would indeed be possible to create a command “echo test” (for example using ln -s /bin/echo '/bin/echo test')

        2. Since the command does not exist on your system (and indeed, on any other sane *nix system), zsh helpfully prints an error message to this effect.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 24 '18 at 5:20









        l0b0l0b0

        34.1k1585147




        34.1k1585147
































            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%2f53453400%2fdifference-between-and-on-the-linux-terminal-zsh-shell%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

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'