Command not found after setting source in bash script [duplicate]











up vote
1
down vote

favorite













This question already has an answer here:




  • Cannot successfully source .bashrc from a shell script

    5 answers




Following the instructions here, and everything works fine manually. However, when I use the instructions in a bash script, I get rbenv command not found because the source ~/.bashrc didn't execute correctly. What's going on? Feel like I've run into this before on something else...



*Execute bit is set, ran dos2unix, and have #!/bin/bash at the top.



#!/bin/bash

git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
rbenv install 2.3.1









share|improve this question















marked as duplicate by muru bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 2 at 4:13


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















    up vote
    1
    down vote

    favorite













    This question already has an answer here:




    • Cannot successfully source .bashrc from a shell script

      5 answers




    Following the instructions here, and everything works fine manually. However, when I use the instructions in a bash script, I get rbenv command not found because the source ~/.bashrc didn't execute correctly. What's going on? Feel like I've run into this before on something else...



    *Execute bit is set, ran dos2unix, and have #!/bin/bash at the top.



    #!/bin/bash

    git clone https://github.com/rbenv/rbenv.git ~/.rbenv
    echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
    echo 'eval "$(rbenv init -)"' >> ~/.bashrc
    source ~/.bashrc
    git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
    rbenv install 2.3.1









    share|improve this question















    marked as duplicate by muru bash
    Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Dec 2 at 4:13


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite












      This question already has an answer here:




      • Cannot successfully source .bashrc from a shell script

        5 answers




      Following the instructions here, and everything works fine manually. However, when I use the instructions in a bash script, I get rbenv command not found because the source ~/.bashrc didn't execute correctly. What's going on? Feel like I've run into this before on something else...



      *Execute bit is set, ran dos2unix, and have #!/bin/bash at the top.



      #!/bin/bash

      git clone https://github.com/rbenv/rbenv.git ~/.rbenv
      echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
      echo 'eval "$(rbenv init -)"' >> ~/.bashrc
      source ~/.bashrc
      git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
      rbenv install 2.3.1









      share|improve this question
















      This question already has an answer here:




      • Cannot successfully source .bashrc from a shell script

        5 answers




      Following the instructions here, and everything works fine manually. However, when I use the instructions in a bash script, I get rbenv command not found because the source ~/.bashrc didn't execute correctly. What's going on? Feel like I've run into this before on something else...



      *Execute bit is set, ran dos2unix, and have #!/bin/bash at the top.



      #!/bin/bash

      git clone https://github.com/rbenv/rbenv.git ~/.rbenv
      echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
      echo 'eval "$(rbenv init -)"' >> ~/.bashrc
      source ~/.bashrc
      git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
      rbenv install 2.3.1




      This question already has an answer here:




      • Cannot successfully source .bashrc from a shell script

        5 answers








      command-line bash scripts source






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 1 at 22:13

























      asked Dec 1 at 21:17









      user58446

      83




      83




      marked as duplicate by muru bash
      Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Dec 2 at 4:13


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by muru bash
      Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Dec 2 at 4:13


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          That’s because the script subshell doesn‘t run interactively, in which case the ~/.bashrc is set to do nothing by default. You can either use any of the workarounds explained in this and this answer or simply call rbenv with the full path on the last line:



          $HOME/.rbenv/bin/rbenv install 2.3.1


          Note that for Cosmic onwards there’s an rbenv package in the repositories.






          share|improve this answer






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote



            accepted










            That’s because the script subshell doesn‘t run interactively, in which case the ~/.bashrc is set to do nothing by default. You can either use any of the workarounds explained in this and this answer or simply call rbenv with the full path on the last line:



            $HOME/.rbenv/bin/rbenv install 2.3.1


            Note that for Cosmic onwards there’s an rbenv package in the repositories.






            share|improve this answer



























              up vote
              0
              down vote



              accepted










              That’s because the script subshell doesn‘t run interactively, in which case the ~/.bashrc is set to do nothing by default. You can either use any of the workarounds explained in this and this answer or simply call rbenv with the full path on the last line:



              $HOME/.rbenv/bin/rbenv install 2.3.1


              Note that for Cosmic onwards there’s an rbenv package in the repositories.






              share|improve this answer

























                up vote
                0
                down vote



                accepted







                up vote
                0
                down vote



                accepted






                That’s because the script subshell doesn‘t run interactively, in which case the ~/.bashrc is set to do nothing by default. You can either use any of the workarounds explained in this and this answer or simply call rbenv with the full path on the last line:



                $HOME/.rbenv/bin/rbenv install 2.3.1


                Note that for Cosmic onwards there’s an rbenv package in the repositories.






                share|improve this answer














                That’s because the script subshell doesn‘t run interactively, in which case the ~/.bashrc is set to do nothing by default. You can either use any of the workarounds explained in this and this answer or simply call rbenv with the full path on the last line:



                $HOME/.rbenv/bin/rbenv install 2.3.1


                Note that for Cosmic onwards there’s an rbenv package in the repositories.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 2 at 8:05

























                answered Dec 1 at 23:12









                dessert

                21.7k55896




                21.7k55896















                    Popular posts from this blog

                    Quarter-circle Tiles

                    build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

                    Mont Emei