SSH script does not have access to full path 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 margin-bottom:0;







up vote
0
down vote

favorite












When I ssh into host and echo $PATH:



$ ssh my@host
$ echo $PATH


I get a different value for $PATH than when I run a script locally:



ssh my@host '
echo $PATH;'


Any idea why?



NOTE: It seems I don't get the full path variable when sshing from a script versus [other] CLI.







share|improve this question

















  • 1




    ssh opens login shell and what happens depends on the shell you use and your setup. For example if you use bash only /etc/profile is processed.
    – Arkadiusz Drabczyk
    Jul 19 at 18:19











  • show us, don't make us guess. What was the output?
    – ctrl-alt-delor
    Jul 19 at 18:56
















up vote
0
down vote

favorite












When I ssh into host and echo $PATH:



$ ssh my@host
$ echo $PATH


I get a different value for $PATH than when I run a script locally:



ssh my@host '
echo $PATH;'


Any idea why?



NOTE: It seems I don't get the full path variable when sshing from a script versus [other] CLI.







share|improve this question

















  • 1




    ssh opens login shell and what happens depends on the shell you use and your setup. For example if you use bash only /etc/profile is processed.
    – Arkadiusz Drabczyk
    Jul 19 at 18:19











  • show us, don't make us guess. What was the output?
    – ctrl-alt-delor
    Jul 19 at 18:56












up vote
0
down vote

favorite









up vote
0
down vote

favorite











When I ssh into host and echo $PATH:



$ ssh my@host
$ echo $PATH


I get a different value for $PATH than when I run a script locally:



ssh my@host '
echo $PATH;'


Any idea why?



NOTE: It seems I don't get the full path variable when sshing from a script versus [other] CLI.







share|improve this question













When I ssh into host and echo $PATH:



$ ssh my@host
$ echo $PATH


I get a different value for $PATH than when I run a script locally:



ssh my@host '
echo $PATH;'


Any idea why?



NOTE: It seems I don't get the full path variable when sshing from a script versus [other] CLI.









share|improve this question












share|improve this question




share|improve this question








edited Jul 19 at 19:26









slm♦

232k65479649




232k65479649









asked Jul 19 at 18:14









the_prole

1113




1113







  • 1




    ssh opens login shell and what happens depends on the shell you use and your setup. For example if you use bash only /etc/profile is processed.
    – Arkadiusz Drabczyk
    Jul 19 at 18:19











  • show us, don't make us guess. What was the output?
    – ctrl-alt-delor
    Jul 19 at 18:56












  • 1




    ssh opens login shell and what happens depends on the shell you use and your setup. For example if you use bash only /etc/profile is processed.
    – Arkadiusz Drabczyk
    Jul 19 at 18:19











  • show us, don't make us guess. What was the output?
    – ctrl-alt-delor
    Jul 19 at 18:56







1




1




ssh opens login shell and what happens depends on the shell you use and your setup. For example if you use bash only /etc/profile is processed.
– Arkadiusz Drabczyk
Jul 19 at 18:19





ssh opens login shell and what happens depends on the shell you use and your setup. For example if you use bash only /etc/profile is processed.
– Arkadiusz Drabczyk
Jul 19 at 18:19













show us, don't make us guess. What was the output?
– ctrl-alt-delor
Jul 19 at 18:56




show us, don't make us guess. What was the output?
– ctrl-alt-delor
Jul 19 at 18:56










2 Answers
2






active

oldest

votes

















up vote
0
down vote













This is due to the fact that when you run a command through ssh (ssh user@host 'command') it opens a non-login shell. An excellent breakdown of the differences between a login shell and a non-login shell can be found at this question. Essentially, what is causing you issue is that when you run the command through ssh your ~/.bash_profile is not sourced, meaning any modifications to the path it makes will not be available.



The solution is to either move these into your ~/.bashrc, which is sourced on opening a non-login shell, or as you found out, sourcing your .bash_profile directly in the script.






share|improve this answer




























    up vote
    0
    down vote













    Adding this line to bash script worked



    source ~/.bash_profile


    source






    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%2f457275%2fssh-script-does-not-have-access-to-full-path-variable%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
      0
      down vote













      This is due to the fact that when you run a command through ssh (ssh user@host 'command') it opens a non-login shell. An excellent breakdown of the differences between a login shell and a non-login shell can be found at this question. Essentially, what is causing you issue is that when you run the command through ssh your ~/.bash_profile is not sourced, meaning any modifications to the path it makes will not be available.



      The solution is to either move these into your ~/.bashrc, which is sourced on opening a non-login shell, or as you found out, sourcing your .bash_profile directly in the script.






      share|improve this answer

























        up vote
        0
        down vote













        This is due to the fact that when you run a command through ssh (ssh user@host 'command') it opens a non-login shell. An excellent breakdown of the differences between a login shell and a non-login shell can be found at this question. Essentially, what is causing you issue is that when you run the command through ssh your ~/.bash_profile is not sourced, meaning any modifications to the path it makes will not be available.



        The solution is to either move these into your ~/.bashrc, which is sourced on opening a non-login shell, or as you found out, sourcing your .bash_profile directly in the script.






        share|improve this answer























          up vote
          0
          down vote










          up vote
          0
          down vote









          This is due to the fact that when you run a command through ssh (ssh user@host 'command') it opens a non-login shell. An excellent breakdown of the differences between a login shell and a non-login shell can be found at this question. Essentially, what is causing you issue is that when you run the command through ssh your ~/.bash_profile is not sourced, meaning any modifications to the path it makes will not be available.



          The solution is to either move these into your ~/.bashrc, which is sourced on opening a non-login shell, or as you found out, sourcing your .bash_profile directly in the script.






          share|improve this answer













          This is due to the fact that when you run a command through ssh (ssh user@host 'command') it opens a non-login shell. An excellent breakdown of the differences between a login shell and a non-login shell can be found at this question. Essentially, what is causing you issue is that when you run the command through ssh your ~/.bash_profile is not sourced, meaning any modifications to the path it makes will not be available.



          The solution is to either move these into your ~/.bashrc, which is sourced on opening a non-login shell, or as you found out, sourcing your .bash_profile directly in the script.







          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered Jul 19 at 18:44









          Thegs

          31516




          31516






















              up vote
              0
              down vote













              Adding this line to bash script worked



              source ~/.bash_profile


              source






              share|improve this answer



























                up vote
                0
                down vote













                Adding this line to bash script worked



                source ~/.bash_profile


                source






                share|improve this answer

























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Adding this line to bash script worked



                  source ~/.bash_profile


                  source






                  share|improve this answer















                  Adding this line to bash script worked



                  source ~/.bash_profile


                  source







                  share|improve this answer















                  share|improve this answer



                  share|improve this answer








                  edited Jul 19 at 19:20









                  slm♦

                  232k65479649




                  232k65479649











                  answered Jul 19 at 18:30









                  the_prole

                  1113




                  1113






















                       

                      draft saved


                      draft discarded


























                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f457275%2fssh-script-does-not-have-access-to-full-path-variable%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?

                      Bahrain

                      Postfix configuration issue with fips on centos 7; mailgun relay