Why can't I use “$whoami” as a variable in “chown $whoami path”?

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











up vote
-1
down vote

favorite












Why doesn't this work?



[my_user@archlinux ~]$ sudo chown -R $whoami /my_folder/path1/path2
chown: missing operand after ‘/my_folder/path1/path2’
Try 'chown --help' for more information.


[my_user@archlinux ~]$ sudo chown -R my_user /my_folder/path1/path2
[my_user@archlinux ~]$ $whoami
[my_user@archlinux ~]$ $whoami


But:



[my_user@archlinux ~]$ whoami
my_user


How to use the result of whoami in sudo chown -R?










share|improve this question



























    up vote
    -1
    down vote

    favorite












    Why doesn't this work?



    [my_user@archlinux ~]$ sudo chown -R $whoami /my_folder/path1/path2
    chown: missing operand after ‘/my_folder/path1/path2’
    Try 'chown --help' for more information.


    [my_user@archlinux ~]$ sudo chown -R my_user /my_folder/path1/path2
    [my_user@archlinux ~]$ $whoami
    [my_user@archlinux ~]$ $whoami


    But:



    [my_user@archlinux ~]$ whoami
    my_user


    How to use the result of whoami in sudo chown -R?










    share|improve this question

























      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      Why doesn't this work?



      [my_user@archlinux ~]$ sudo chown -R $whoami /my_folder/path1/path2
      chown: missing operand after ‘/my_folder/path1/path2’
      Try 'chown --help' for more information.


      [my_user@archlinux ~]$ sudo chown -R my_user /my_folder/path1/path2
      [my_user@archlinux ~]$ $whoami
      [my_user@archlinux ~]$ $whoami


      But:



      [my_user@archlinux ~]$ whoami
      my_user


      How to use the result of whoami in sudo chown -R?










      share|improve this question















      Why doesn't this work?



      [my_user@archlinux ~]$ sudo chown -R $whoami /my_folder/path1/path2
      chown: missing operand after ‘/my_folder/path1/path2’
      Try 'chown --help' for more information.


      [my_user@archlinux ~]$ sudo chown -R my_user /my_folder/path1/path2
      [my_user@archlinux ~]$ $whoami
      [my_user@archlinux ~]$ $whoami


      But:



      [my_user@archlinux ~]$ whoami
      my_user


      How to use the result of whoami in sudo chown -R?







      bash variable






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 17 at 19:44









      ilkkachu

      53.7k781146




      53.7k781146










      asked Nov 17 at 18:57









      nylypej

      1294




      1294




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          5
          down vote













          The variable $whoami does not have a value. You may give it a value with



          whoami=$(whoami)


          but in this case you may want to use the command substitution $(whoami) directly:



          sudo chown -R "$(whoami)" /my_folder/path1/path2


          A command substitution, $(...), expands to the output of the command within (minus any trailing newline).



          The variable $LOGNAME (and/or $USER) should have the same value as is returned by whoami, which means that you could also do



          sudo chown -R "$LOGNAME" /my_folder/path1/path2





          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: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            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%2funix.stackexchange.com%2fquestions%2f482379%2fwhy-cant-i-use-whoami-as-a-variable-in-chown-whoami-path%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








            up vote
            5
            down vote













            The variable $whoami does not have a value. You may give it a value with



            whoami=$(whoami)


            but in this case you may want to use the command substitution $(whoami) directly:



            sudo chown -R "$(whoami)" /my_folder/path1/path2


            A command substitution, $(...), expands to the output of the command within (minus any trailing newline).



            The variable $LOGNAME (and/or $USER) should have the same value as is returned by whoami, which means that you could also do



            sudo chown -R "$LOGNAME" /my_folder/path1/path2





            share|improve this answer
























              up vote
              5
              down vote













              The variable $whoami does not have a value. You may give it a value with



              whoami=$(whoami)


              but in this case you may want to use the command substitution $(whoami) directly:



              sudo chown -R "$(whoami)" /my_folder/path1/path2


              A command substitution, $(...), expands to the output of the command within (minus any trailing newline).



              The variable $LOGNAME (and/or $USER) should have the same value as is returned by whoami, which means that you could also do



              sudo chown -R "$LOGNAME" /my_folder/path1/path2





              share|improve this answer






















                up vote
                5
                down vote










                up vote
                5
                down vote









                The variable $whoami does not have a value. You may give it a value with



                whoami=$(whoami)


                but in this case you may want to use the command substitution $(whoami) directly:



                sudo chown -R "$(whoami)" /my_folder/path1/path2


                A command substitution, $(...), expands to the output of the command within (minus any trailing newline).



                The variable $LOGNAME (and/or $USER) should have the same value as is returned by whoami, which means that you could also do



                sudo chown -R "$LOGNAME" /my_folder/path1/path2





                share|improve this answer












                The variable $whoami does not have a value. You may give it a value with



                whoami=$(whoami)


                but in this case you may want to use the command substitution $(whoami) directly:



                sudo chown -R "$(whoami)" /my_folder/path1/path2


                A command substitution, $(...), expands to the output of the command within (minus any trailing newline).



                The variable $LOGNAME (and/or $USER) should have the same value as is returned by whoami, which means that you could also do



                sudo chown -R "$LOGNAME" /my_folder/path1/path2






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 17 at 19:01









                Kusalananda

                116k15218352




                116k15218352



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f482379%2fwhy-cant-i-use-whoami-as-a-variable-in-chown-whoami-path%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

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

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay