Bash Command Not Found Error with $variable

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





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















108 ps --ppid $process | while read -r line ; do
109 #echo $line | awk 'print $1;
110 child=$($line | awk 'print $1;')
111 echo $child
113 done


Running this code gives me the following error:



line 111: 3405: command not found


But if I uncomment line 109 it prints the correct value without an error










share|improve this question



















  • 1





    What are you expecting to happen? without the echo $line will be treated as a command to run, apparently the command 3405 in your example.

    – Eric Renouf
    Nov 27 '16 at 1:52






  • 3





    This smacks of an XY problem to me, what is it that you're actually trying to do?

    – Eric Renouf
    Nov 27 '16 at 1:54






  • 1





    line 110 looks fishy to me (did you mean to 'echo $line' to awk?)

    – Jeff Schaller
    Nov 27 '16 at 2:00











  • Post complete code that reproduces the problem and explain what you want the script to do.

    – Gilles
    Nov 27 '16 at 21:19

















0















108 ps --ppid $process | while read -r line ; do
109 #echo $line | awk 'print $1;
110 child=$($line | awk 'print $1;')
111 echo $child
113 done


Running this code gives me the following error:



line 111: 3405: command not found


But if I uncomment line 109 it prints the correct value without an error










share|improve this question



















  • 1





    What are you expecting to happen? without the echo $line will be treated as a command to run, apparently the command 3405 in your example.

    – Eric Renouf
    Nov 27 '16 at 1:52






  • 3





    This smacks of an XY problem to me, what is it that you're actually trying to do?

    – Eric Renouf
    Nov 27 '16 at 1:54






  • 1





    line 110 looks fishy to me (did you mean to 'echo $line' to awk?)

    – Jeff Schaller
    Nov 27 '16 at 2:00











  • Post complete code that reproduces the problem and explain what you want the script to do.

    – Gilles
    Nov 27 '16 at 21:19













0












0








0








108 ps --ppid $process | while read -r line ; do
109 #echo $line | awk 'print $1;
110 child=$($line | awk 'print $1;')
111 echo $child
113 done


Running this code gives me the following error:



line 111: 3405: command not found


But if I uncomment line 109 it prints the correct value without an error










share|improve this question
















108 ps --ppid $process | while read -r line ; do
109 #echo $line | awk 'print $1;
110 child=$($line | awk 'print $1;')
111 echo $child
113 done


Running this code gives me the following error:



line 111: 3405: command not found


But if I uncomment line 109 it prints the correct value without an error







bash command-not-found






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 27 '16 at 1:44









techraf

4,303102243




4,303102243










asked Nov 27 '16 at 1:43









shav017shav017

41




41







  • 1





    What are you expecting to happen? without the echo $line will be treated as a command to run, apparently the command 3405 in your example.

    – Eric Renouf
    Nov 27 '16 at 1:52






  • 3





    This smacks of an XY problem to me, what is it that you're actually trying to do?

    – Eric Renouf
    Nov 27 '16 at 1:54






  • 1





    line 110 looks fishy to me (did you mean to 'echo $line' to awk?)

    – Jeff Schaller
    Nov 27 '16 at 2:00











  • Post complete code that reproduces the problem and explain what you want the script to do.

    – Gilles
    Nov 27 '16 at 21:19












  • 1





    What are you expecting to happen? without the echo $line will be treated as a command to run, apparently the command 3405 in your example.

    – Eric Renouf
    Nov 27 '16 at 1:52






  • 3





    This smacks of an XY problem to me, what is it that you're actually trying to do?

    – Eric Renouf
    Nov 27 '16 at 1:54






  • 1





    line 110 looks fishy to me (did you mean to 'echo $line' to awk?)

    – Jeff Schaller
    Nov 27 '16 at 2:00











  • Post complete code that reproduces the problem and explain what you want the script to do.

    – Gilles
    Nov 27 '16 at 21:19







1




1





What are you expecting to happen? without the echo $line will be treated as a command to run, apparently the command 3405 in your example.

– Eric Renouf
Nov 27 '16 at 1:52





What are you expecting to happen? without the echo $line will be treated as a command to run, apparently the command 3405 in your example.

– Eric Renouf
Nov 27 '16 at 1:52




3




3





This smacks of an XY problem to me, what is it that you're actually trying to do?

– Eric Renouf
Nov 27 '16 at 1:54





This smacks of an XY problem to me, what is it that you're actually trying to do?

– Eric Renouf
Nov 27 '16 at 1:54




1




1





line 110 looks fishy to me (did you mean to 'echo $line' to awk?)

– Jeff Schaller
Nov 27 '16 at 2:00





line 110 looks fishy to me (did you mean to 'echo $line' to awk?)

– Jeff Schaller
Nov 27 '16 at 2:00













Post complete code that reproduces the problem and explain what you want the script to do.

– Gilles
Nov 27 '16 at 21:19





Post complete code that reproduces the problem and explain what you want the script to do.

– Gilles
Nov 27 '16 at 21:19










2 Answers
2






active

oldest

votes


















0














Fix it...



ps --ppid $process | while read -r line ; do
child=$(echo $line | awk 'print $1')
done





share|improve this answer






























    0














    The issue is that you're not actually giving the value in $line to awk. Instead you try to execute it as a command.



    If all you want to do is output the child processes of a process with a certain PID, then you don't need to loop:



    ps --ppid "$process" -o pid=


    This would get the list of processes that has $process as their PPID, and for each output their PID.



    Also related:



    • Why is using a shell loop to process text considered bad practice?





    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',
      autoActivateHeartbeat: false,
      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%2f326289%2fbash-command-not-found-error-with-variable%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









      0














      Fix it...



      ps --ppid $process | while read -r line ; do
      child=$(echo $line | awk 'print $1')
      done





      share|improve this answer



























        0














        Fix it...



        ps --ppid $process | while read -r line ; do
        child=$(echo $line | awk 'print $1')
        done





        share|improve this answer

























          0












          0








          0







          Fix it...



          ps --ppid $process | while read -r line ; do
          child=$(echo $line | awk 'print $1')
          done





          share|improve this answer













          Fix it...



          ps --ppid $process | while read -r line ; do
          child=$(echo $line | awk 'print $1')
          done






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 27 '16 at 2:00









          jas-jas-

          73238




          73238























              0














              The issue is that you're not actually giving the value in $line to awk. Instead you try to execute it as a command.



              If all you want to do is output the child processes of a process with a certain PID, then you don't need to loop:



              ps --ppid "$process" -o pid=


              This would get the list of processes that has $process as their PPID, and for each output their PID.



              Also related:



              • Why is using a shell loop to process text considered bad practice?





              share|improve this answer



























                0














                The issue is that you're not actually giving the value in $line to awk. Instead you try to execute it as a command.



                If all you want to do is output the child processes of a process with a certain PID, then you don't need to loop:



                ps --ppid "$process" -o pid=


                This would get the list of processes that has $process as their PPID, and for each output their PID.



                Also related:



                • Why is using a shell loop to process text considered bad practice?





                share|improve this answer

























                  0












                  0








                  0







                  The issue is that you're not actually giving the value in $line to awk. Instead you try to execute it as a command.



                  If all you want to do is output the child processes of a process with a certain PID, then you don't need to loop:



                  ps --ppid "$process" -o pid=


                  This would get the list of processes that has $process as their PPID, and for each output their PID.



                  Also related:



                  • Why is using a shell loop to process text considered bad practice?





                  share|improve this answer













                  The issue is that you're not actually giving the value in $line to awk. Instead you try to execute it as a command.



                  If all you want to do is output the child processes of a process with a certain PID, then you don't need to loop:



                  ps --ppid "$process" -o pid=


                  This would get the list of processes that has $process as their PPID, and for each output their PID.



                  Also related:



                  • Why is using a shell loop to process text considered bad practice?






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 17 at 14:15









                  KusalanandaKusalananda

                  142k18264440




                  142k18264440



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • 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%2funix.stackexchange.com%2fquestions%2f326289%2fbash-command-not-found-error-with-variable%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

                      Peggy Mitchell

                      Palaiologos

                      The Forum (Inglewood, California)