How to display current path in command prompt in linux's sh (not bash)?











up vote
35
down vote

favorite
12












I would like to display current path in sh prompt (not bash shell), which currently just shows "#",
I tried with introducing this



env PS1="$(whoami)@$(hostname):$(pwd)"


and



set PS1="$(whoami)@$(hostname):$(pwd)"


in /etc/profile.



But as obvious this does not refresh when the the directory is changed or user changes.
Please suggest a way to make this dynamic.










share|improve this question




















  • 1




    Note that each $() runs a separate program; it would be faster to use environment variables, such as $LOGNAME, $HOSTNAME and $PWD instead.
    – grawity
    May 29 '13 at 12:00










  • One answer was to use single quotes instead of double quotes, however, that's quite the full correct answer. What you really want to do is defer evaluation of the code inside your prompt until the prompt is used.
    – MaasSql
    Oct 27 '14 at 14:40










  • All you need is to use export "PS1="$(whoami)@$(hostname):$(pwd) >" then edit /etc/profile and append this line at the end.
    – SDsolar
    Mar 29 '17 at 19:25

















up vote
35
down vote

favorite
12












I would like to display current path in sh prompt (not bash shell), which currently just shows "#",
I tried with introducing this



env PS1="$(whoami)@$(hostname):$(pwd)"


and



set PS1="$(whoami)@$(hostname):$(pwd)"


in /etc/profile.



But as obvious this does not refresh when the the directory is changed or user changes.
Please suggest a way to make this dynamic.










share|improve this question




















  • 1




    Note that each $() runs a separate program; it would be faster to use environment variables, such as $LOGNAME, $HOSTNAME and $PWD instead.
    – grawity
    May 29 '13 at 12:00










  • One answer was to use single quotes instead of double quotes, however, that's quite the full correct answer. What you really want to do is defer evaluation of the code inside your prompt until the prompt is used.
    – MaasSql
    Oct 27 '14 at 14:40










  • All you need is to use export "PS1="$(whoami)@$(hostname):$(pwd) >" then edit /etc/profile and append this line at the end.
    – SDsolar
    Mar 29 '17 at 19:25















up vote
35
down vote

favorite
12









up vote
35
down vote

favorite
12






12





I would like to display current path in sh prompt (not bash shell), which currently just shows "#",
I tried with introducing this



env PS1="$(whoami)@$(hostname):$(pwd)"


and



set PS1="$(whoami)@$(hostname):$(pwd)"


in /etc/profile.



But as obvious this does not refresh when the the directory is changed or user changes.
Please suggest a way to make this dynamic.










share|improve this question















I would like to display current path in sh prompt (not bash shell), which currently just shows "#",
I tried with introducing this



env PS1="$(whoami)@$(hostname):$(pwd)"


and



set PS1="$(whoami)@$(hostname):$(pwd)"


in /etc/profile.



But as obvious this does not refresh when the the directory is changed or user changes.
Please suggest a way to make this dynamic.







linux shell sh busybox






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 29 '13 at 11:01









mpy

17.7k45270




17.7k45270










asked May 29 '13 at 9:56









Bleamer

286137




286137








  • 1




    Note that each $() runs a separate program; it would be faster to use environment variables, such as $LOGNAME, $HOSTNAME and $PWD instead.
    – grawity
    May 29 '13 at 12:00










  • One answer was to use single quotes instead of double quotes, however, that's quite the full correct answer. What you really want to do is defer evaluation of the code inside your prompt until the prompt is used.
    – MaasSql
    Oct 27 '14 at 14:40










  • All you need is to use export "PS1="$(whoami)@$(hostname):$(pwd) >" then edit /etc/profile and append this line at the end.
    – SDsolar
    Mar 29 '17 at 19:25
















  • 1




    Note that each $() runs a separate program; it would be faster to use environment variables, such as $LOGNAME, $HOSTNAME and $PWD instead.
    – grawity
    May 29 '13 at 12:00










  • One answer was to use single quotes instead of double quotes, however, that's quite the full correct answer. What you really want to do is defer evaluation of the code inside your prompt until the prompt is used.
    – MaasSql
    Oct 27 '14 at 14:40










  • All you need is to use export "PS1="$(whoami)@$(hostname):$(pwd) >" then edit /etc/profile and append this line at the end.
    – SDsolar
    Mar 29 '17 at 19:25










1




1




Note that each $() runs a separate program; it would be faster to use environment variables, such as $LOGNAME, $HOSTNAME and $PWD instead.
– grawity
May 29 '13 at 12:00




Note that each $() runs a separate program; it would be faster to use environment variables, such as $LOGNAME, $HOSTNAME and $PWD instead.
– grawity
May 29 '13 at 12:00












One answer was to use single quotes instead of double quotes, however, that's quite the full correct answer. What you really want to do is defer evaluation of the code inside your prompt until the prompt is used.
– MaasSql
Oct 27 '14 at 14:40




One answer was to use single quotes instead of double quotes, however, that's quite the full correct answer. What you really want to do is defer evaluation of the code inside your prompt until the prompt is used.
– MaasSql
Oct 27 '14 at 14:40












All you need is to use export "PS1="$(whoami)@$(hostname):$(pwd) >" then edit /etc/profile and append this line at the end.
– SDsolar
Mar 29 '17 at 19:25






All you need is to use export "PS1="$(whoami)@$(hostname):$(pwd) >" then edit /etc/profile and append this line at the end.
– SDsolar
Mar 29 '17 at 19:25












6 Answers
6






active

oldest

votes

















up vote
59
down vote



accepted










Command substitutions in double quotes " get expanded immediately. That is not what you want for your prompt. Single quotes ' will preserve the substitutions in $PS1 which then get only expanded when displaying the prompt. Hence this should work:



export PS1='$(whoami)@$(hostname):$(pwd)'


If you want the usual dollar sign and a space at the end of your prompt, simply add $ at the end (no escaping necessary): export PS1='$(whoami)@$(hostname):$(pwd)$ '






share|improve this answer



















  • 1




    Worked like a charm after changing 'set' to 'export' in your answer export PS1='$(whoami)@$(hostname):$(pwd)$' I saved the change s to /etc/profile. Thank you.
    – Bleamer
    May 29 '13 at 10:22












  • @Bleamer: set worked for me (but I didn't had a native sh). But I'll change it to export to comply with your setup.
    – mpy
    May 29 '13 at 11:01






  • 1




    Is there any way to make this permanent? Currently I have to do it each time I log in. Thanks!
    – the.ufon
    Sep 2 '14 at 7:07






  • 2




    You have put this line to /etc/profile (see question) or ~/.profile?!
    – mpy
    Sep 2 '14 at 16:39










  • +1, this would need some delimiter at the end, though. As is, you get something like foo@localhost:/home/fools -la when using ls -la.
    – phresnel
    Jan 6 '15 at 10:00


















up vote
11
down vote













sh-4.2$ export PS1="u@h:w>"
jenny@serenity:~>cd /usr/local
jenny@serenity:/usr/local>





share|improve this answer

















  • 1




    I am afraid that works for bash shell not for sh, when i do this I get u@h:w> as my command prompt
    – Bleamer
    May 29 '13 at 10:11








  • 1




    Must be a different sh version; as you can see from the first line, it worked for me in sh 4.2.
    – Jenny D
    May 29 '13 at 10:12






  • 1




    That may be the case. This shell is from Busy Box. Thank you. Appreciate your help though.
    – Bleamer
    May 29 '13 at 10:25












  • @Bleamer, it works for me with BusyBox v1.19.4 built-in shell (ash).
    – cjm
    Sep 11 '13 at 4:26












  • Thank you for response @cjm, though I'll avoid digging further into this.
    – Bleamer
    Sep 27 '13 at 9:34


















up vote
3
down vote













This command works for me.



export PS1="u@h: W:$"


Where
u = username

h = hostname

W Name of present folder (not full path)






share|improve this answer





















  • +1 for W parameter
    – Dimitry K
    Oct 23 at 17:31


















up vote
1
down vote













One answer was to use single quotes instead of double quotes, however, that's not quite the full correct answer. What you really want to do is defer evaluation of the code inside your prompt until the prompt is used.



set PS1="$(pwd)" 


sets the prompt to the working directory as of the set command.



set PS1="$(pwd)" 


does NOT expand $(pwd). Instead, PS1 is set to the literal value of $(pwd).



Test / Understand this by running:



echo $PS1


. If you see the string : $pwd, your prompt works. If you see the literal path, the prompt is broken because it has been statically set






share|improve this answer




























    up vote
    1
    down vote













    Use the below command to set is like in the cpanel.



    export PS1='$(whoami)@${HOSTNAME%%.*} [$(pwd)]# '






    share|improve this answer























    • Thanks! None of the other options above worked. This one did. Was driving me crazy. Thanks for saving my sanity. HA!
      – Lee_Str
      Jun 14 '16 at 12:57


















    up vote
    0
    down vote













    One might consider to pimp the prompt by adding some colors. For instance:



    export PS1='[e[0;36m]u[e[0m]@[e[0;33m]h[e[0m]:[e[0;35m]w[e[0m]$ '





    share|improve this answer








    New contributor




    Arvid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.


















      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "3"
      };
      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: 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%2fsuperuser.com%2fquestions%2f601181%2fhow-to-display-current-path-in-command-prompt-in-linuxs-sh-not-bash%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      6 Answers
      6






      active

      oldest

      votes








      6 Answers
      6






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      59
      down vote



      accepted










      Command substitutions in double quotes " get expanded immediately. That is not what you want for your prompt. Single quotes ' will preserve the substitutions in $PS1 which then get only expanded when displaying the prompt. Hence this should work:



      export PS1='$(whoami)@$(hostname):$(pwd)'


      If you want the usual dollar sign and a space at the end of your prompt, simply add $ at the end (no escaping necessary): export PS1='$(whoami)@$(hostname):$(pwd)$ '






      share|improve this answer



















      • 1




        Worked like a charm after changing 'set' to 'export' in your answer export PS1='$(whoami)@$(hostname):$(pwd)$' I saved the change s to /etc/profile. Thank you.
        – Bleamer
        May 29 '13 at 10:22












      • @Bleamer: set worked for me (but I didn't had a native sh). But I'll change it to export to comply with your setup.
        – mpy
        May 29 '13 at 11:01






      • 1




        Is there any way to make this permanent? Currently I have to do it each time I log in. Thanks!
        – the.ufon
        Sep 2 '14 at 7:07






      • 2




        You have put this line to /etc/profile (see question) or ~/.profile?!
        – mpy
        Sep 2 '14 at 16:39










      • +1, this would need some delimiter at the end, though. As is, you get something like foo@localhost:/home/fools -la when using ls -la.
        – phresnel
        Jan 6 '15 at 10:00















      up vote
      59
      down vote



      accepted










      Command substitutions in double quotes " get expanded immediately. That is not what you want for your prompt. Single quotes ' will preserve the substitutions in $PS1 which then get only expanded when displaying the prompt. Hence this should work:



      export PS1='$(whoami)@$(hostname):$(pwd)'


      If you want the usual dollar sign and a space at the end of your prompt, simply add $ at the end (no escaping necessary): export PS1='$(whoami)@$(hostname):$(pwd)$ '






      share|improve this answer



















      • 1




        Worked like a charm after changing 'set' to 'export' in your answer export PS1='$(whoami)@$(hostname):$(pwd)$' I saved the change s to /etc/profile. Thank you.
        – Bleamer
        May 29 '13 at 10:22












      • @Bleamer: set worked for me (but I didn't had a native sh). But I'll change it to export to comply with your setup.
        – mpy
        May 29 '13 at 11:01






      • 1




        Is there any way to make this permanent? Currently I have to do it each time I log in. Thanks!
        – the.ufon
        Sep 2 '14 at 7:07






      • 2




        You have put this line to /etc/profile (see question) or ~/.profile?!
        – mpy
        Sep 2 '14 at 16:39










      • +1, this would need some delimiter at the end, though. As is, you get something like foo@localhost:/home/fools -la when using ls -la.
        – phresnel
        Jan 6 '15 at 10:00













      up vote
      59
      down vote



      accepted







      up vote
      59
      down vote



      accepted






      Command substitutions in double quotes " get expanded immediately. That is not what you want for your prompt. Single quotes ' will preserve the substitutions in $PS1 which then get only expanded when displaying the prompt. Hence this should work:



      export PS1='$(whoami)@$(hostname):$(pwd)'


      If you want the usual dollar sign and a space at the end of your prompt, simply add $ at the end (no escaping necessary): export PS1='$(whoami)@$(hostname):$(pwd)$ '






      share|improve this answer














      Command substitutions in double quotes " get expanded immediately. That is not what you want for your prompt. Single quotes ' will preserve the substitutions in $PS1 which then get only expanded when displaying the prompt. Hence this should work:



      export PS1='$(whoami)@$(hostname):$(pwd)'


      If you want the usual dollar sign and a space at the end of your prompt, simply add $ at the end (no escaping necessary): export PS1='$(whoami)@$(hostname):$(pwd)$ '







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Jul 30 '14 at 17:16

























      answered May 29 '13 at 10:05









      mpy

      17.7k45270




      17.7k45270








      • 1




        Worked like a charm after changing 'set' to 'export' in your answer export PS1='$(whoami)@$(hostname):$(pwd)$' I saved the change s to /etc/profile. Thank you.
        – Bleamer
        May 29 '13 at 10:22












      • @Bleamer: set worked for me (but I didn't had a native sh). But I'll change it to export to comply with your setup.
        – mpy
        May 29 '13 at 11:01






      • 1




        Is there any way to make this permanent? Currently I have to do it each time I log in. Thanks!
        – the.ufon
        Sep 2 '14 at 7:07






      • 2




        You have put this line to /etc/profile (see question) or ~/.profile?!
        – mpy
        Sep 2 '14 at 16:39










      • +1, this would need some delimiter at the end, though. As is, you get something like foo@localhost:/home/fools -la when using ls -la.
        – phresnel
        Jan 6 '15 at 10:00














      • 1




        Worked like a charm after changing 'set' to 'export' in your answer export PS1='$(whoami)@$(hostname):$(pwd)$' I saved the change s to /etc/profile. Thank you.
        – Bleamer
        May 29 '13 at 10:22












      • @Bleamer: set worked for me (but I didn't had a native sh). But I'll change it to export to comply with your setup.
        – mpy
        May 29 '13 at 11:01






      • 1




        Is there any way to make this permanent? Currently I have to do it each time I log in. Thanks!
        – the.ufon
        Sep 2 '14 at 7:07






      • 2




        You have put this line to /etc/profile (see question) or ~/.profile?!
        – mpy
        Sep 2 '14 at 16:39










      • +1, this would need some delimiter at the end, though. As is, you get something like foo@localhost:/home/fools -la when using ls -la.
        – phresnel
        Jan 6 '15 at 10:00








      1




      1




      Worked like a charm after changing 'set' to 'export' in your answer export PS1='$(whoami)@$(hostname):$(pwd)$' I saved the change s to /etc/profile. Thank you.
      – Bleamer
      May 29 '13 at 10:22






      Worked like a charm after changing 'set' to 'export' in your answer export PS1='$(whoami)@$(hostname):$(pwd)$' I saved the change s to /etc/profile. Thank you.
      – Bleamer
      May 29 '13 at 10:22














      @Bleamer: set worked for me (but I didn't had a native sh). But I'll change it to export to comply with your setup.
      – mpy
      May 29 '13 at 11:01




      @Bleamer: set worked for me (but I didn't had a native sh). But I'll change it to export to comply with your setup.
      – mpy
      May 29 '13 at 11:01




      1




      1




      Is there any way to make this permanent? Currently I have to do it each time I log in. Thanks!
      – the.ufon
      Sep 2 '14 at 7:07




      Is there any way to make this permanent? Currently I have to do it each time I log in. Thanks!
      – the.ufon
      Sep 2 '14 at 7:07




      2




      2




      You have put this line to /etc/profile (see question) or ~/.profile?!
      – mpy
      Sep 2 '14 at 16:39




      You have put this line to /etc/profile (see question) or ~/.profile?!
      – mpy
      Sep 2 '14 at 16:39












      +1, this would need some delimiter at the end, though. As is, you get something like foo@localhost:/home/fools -la when using ls -la.
      – phresnel
      Jan 6 '15 at 10:00




      +1, this would need some delimiter at the end, though. As is, you get something like foo@localhost:/home/fools -la when using ls -la.
      – phresnel
      Jan 6 '15 at 10:00












      up vote
      11
      down vote













      sh-4.2$ export PS1="u@h:w>"
      jenny@serenity:~>cd /usr/local
      jenny@serenity:/usr/local>





      share|improve this answer

















      • 1




        I am afraid that works for bash shell not for sh, when i do this I get u@h:w> as my command prompt
        – Bleamer
        May 29 '13 at 10:11








      • 1




        Must be a different sh version; as you can see from the first line, it worked for me in sh 4.2.
        – Jenny D
        May 29 '13 at 10:12






      • 1




        That may be the case. This shell is from Busy Box. Thank you. Appreciate your help though.
        – Bleamer
        May 29 '13 at 10:25












      • @Bleamer, it works for me with BusyBox v1.19.4 built-in shell (ash).
        – cjm
        Sep 11 '13 at 4:26












      • Thank you for response @cjm, though I'll avoid digging further into this.
        – Bleamer
        Sep 27 '13 at 9:34















      up vote
      11
      down vote













      sh-4.2$ export PS1="u@h:w>"
      jenny@serenity:~>cd /usr/local
      jenny@serenity:/usr/local>





      share|improve this answer

















      • 1




        I am afraid that works for bash shell not for sh, when i do this I get u@h:w> as my command prompt
        – Bleamer
        May 29 '13 at 10:11








      • 1




        Must be a different sh version; as you can see from the first line, it worked for me in sh 4.2.
        – Jenny D
        May 29 '13 at 10:12






      • 1




        That may be the case. This shell is from Busy Box. Thank you. Appreciate your help though.
        – Bleamer
        May 29 '13 at 10:25












      • @Bleamer, it works for me with BusyBox v1.19.4 built-in shell (ash).
        – cjm
        Sep 11 '13 at 4:26












      • Thank you for response @cjm, though I'll avoid digging further into this.
        – Bleamer
        Sep 27 '13 at 9:34













      up vote
      11
      down vote










      up vote
      11
      down vote









      sh-4.2$ export PS1="u@h:w>"
      jenny@serenity:~>cd /usr/local
      jenny@serenity:/usr/local>





      share|improve this answer












      sh-4.2$ export PS1="u@h:w>"
      jenny@serenity:~>cd /usr/local
      jenny@serenity:/usr/local>






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered May 29 '13 at 10:07









      Jenny D

      492313




      492313








      • 1




        I am afraid that works for bash shell not for sh, when i do this I get u@h:w> as my command prompt
        – Bleamer
        May 29 '13 at 10:11








      • 1




        Must be a different sh version; as you can see from the first line, it worked for me in sh 4.2.
        – Jenny D
        May 29 '13 at 10:12






      • 1




        That may be the case. This shell is from Busy Box. Thank you. Appreciate your help though.
        – Bleamer
        May 29 '13 at 10:25












      • @Bleamer, it works for me with BusyBox v1.19.4 built-in shell (ash).
        – cjm
        Sep 11 '13 at 4:26












      • Thank you for response @cjm, though I'll avoid digging further into this.
        – Bleamer
        Sep 27 '13 at 9:34














      • 1




        I am afraid that works for bash shell not for sh, when i do this I get u@h:w> as my command prompt
        – Bleamer
        May 29 '13 at 10:11








      • 1




        Must be a different sh version; as you can see from the first line, it worked for me in sh 4.2.
        – Jenny D
        May 29 '13 at 10:12






      • 1




        That may be the case. This shell is from Busy Box. Thank you. Appreciate your help though.
        – Bleamer
        May 29 '13 at 10:25












      • @Bleamer, it works for me with BusyBox v1.19.4 built-in shell (ash).
        – cjm
        Sep 11 '13 at 4:26












      • Thank you for response @cjm, though I'll avoid digging further into this.
        – Bleamer
        Sep 27 '13 at 9:34








      1




      1




      I am afraid that works for bash shell not for sh, when i do this I get u@h:w> as my command prompt
      – Bleamer
      May 29 '13 at 10:11






      I am afraid that works for bash shell not for sh, when i do this I get u@h:w> as my command prompt
      – Bleamer
      May 29 '13 at 10:11






      1




      1




      Must be a different sh version; as you can see from the first line, it worked for me in sh 4.2.
      – Jenny D
      May 29 '13 at 10:12




      Must be a different sh version; as you can see from the first line, it worked for me in sh 4.2.
      – Jenny D
      May 29 '13 at 10:12




      1




      1




      That may be the case. This shell is from Busy Box. Thank you. Appreciate your help though.
      – Bleamer
      May 29 '13 at 10:25






      That may be the case. This shell is from Busy Box. Thank you. Appreciate your help though.
      – Bleamer
      May 29 '13 at 10:25














      @Bleamer, it works for me with BusyBox v1.19.4 built-in shell (ash).
      – cjm
      Sep 11 '13 at 4:26






      @Bleamer, it works for me with BusyBox v1.19.4 built-in shell (ash).
      – cjm
      Sep 11 '13 at 4:26














      Thank you for response @cjm, though I'll avoid digging further into this.
      – Bleamer
      Sep 27 '13 at 9:34




      Thank you for response @cjm, though I'll avoid digging further into this.
      – Bleamer
      Sep 27 '13 at 9:34










      up vote
      3
      down vote













      This command works for me.



      export PS1="u@h: W:$"


      Where
      u = username

      h = hostname

      W Name of present folder (not full path)






      share|improve this answer





















      • +1 for W parameter
        – Dimitry K
        Oct 23 at 17:31















      up vote
      3
      down vote













      This command works for me.



      export PS1="u@h: W:$"


      Where
      u = username

      h = hostname

      W Name of present folder (not full path)






      share|improve this answer





















      • +1 for W parameter
        – Dimitry K
        Oct 23 at 17:31













      up vote
      3
      down vote










      up vote
      3
      down vote









      This command works for me.



      export PS1="u@h: W:$"


      Where
      u = username

      h = hostname

      W Name of present folder (not full path)






      share|improve this answer












      This command works for me.



      export PS1="u@h: W:$"


      Where
      u = username

      h = hostname

      W Name of present folder (not full path)







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Jun 25 '17 at 5:27









      rangsiman

      312




      312












      • +1 for W parameter
        – Dimitry K
        Oct 23 at 17:31


















      • +1 for W parameter
        – Dimitry K
        Oct 23 at 17:31
















      +1 for W parameter
      – Dimitry K
      Oct 23 at 17:31




      +1 for W parameter
      – Dimitry K
      Oct 23 at 17:31










      up vote
      1
      down vote













      One answer was to use single quotes instead of double quotes, however, that's not quite the full correct answer. What you really want to do is defer evaluation of the code inside your prompt until the prompt is used.



      set PS1="$(pwd)" 


      sets the prompt to the working directory as of the set command.



      set PS1="$(pwd)" 


      does NOT expand $(pwd). Instead, PS1 is set to the literal value of $(pwd).



      Test / Understand this by running:



      echo $PS1


      . If you see the string : $pwd, your prompt works. If you see the literal path, the prompt is broken because it has been statically set






      share|improve this answer

























        up vote
        1
        down vote













        One answer was to use single quotes instead of double quotes, however, that's not quite the full correct answer. What you really want to do is defer evaluation of the code inside your prompt until the prompt is used.



        set PS1="$(pwd)" 


        sets the prompt to the working directory as of the set command.



        set PS1="$(pwd)" 


        does NOT expand $(pwd). Instead, PS1 is set to the literal value of $(pwd).



        Test / Understand this by running:



        echo $PS1


        . If you see the string : $pwd, your prompt works. If you see the literal path, the prompt is broken because it has been statically set






        share|improve this answer























          up vote
          1
          down vote










          up vote
          1
          down vote









          One answer was to use single quotes instead of double quotes, however, that's not quite the full correct answer. What you really want to do is defer evaluation of the code inside your prompt until the prompt is used.



          set PS1="$(pwd)" 


          sets the prompt to the working directory as of the set command.



          set PS1="$(pwd)" 


          does NOT expand $(pwd). Instead, PS1 is set to the literal value of $(pwd).



          Test / Understand this by running:



          echo $PS1


          . If you see the string : $pwd, your prompt works. If you see the literal path, the prompt is broken because it has been statically set






          share|improve this answer












          One answer was to use single quotes instead of double quotes, however, that's not quite the full correct answer. What you really want to do is defer evaluation of the code inside your prompt until the prompt is used.



          set PS1="$(pwd)" 


          sets the prompt to the working directory as of the set command.



          set PS1="$(pwd)" 


          does NOT expand $(pwd). Instead, PS1 is set to the literal value of $(pwd).



          Test / Understand this by running:



          echo $PS1


          . If you see the string : $pwd, your prompt works. If you see the literal path, the prompt is broken because it has been statically set







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Oct 27 '14 at 14:49









          MaasSql

          1114




          1114






















              up vote
              1
              down vote













              Use the below command to set is like in the cpanel.



              export PS1='$(whoami)@${HOSTNAME%%.*} [$(pwd)]# '






              share|improve this answer























              • Thanks! None of the other options above worked. This one did. Was driving me crazy. Thanks for saving my sanity. HA!
                – Lee_Str
                Jun 14 '16 at 12:57















              up vote
              1
              down vote













              Use the below command to set is like in the cpanel.



              export PS1='$(whoami)@${HOSTNAME%%.*} [$(pwd)]# '






              share|improve this answer























              • Thanks! None of the other options above worked. This one did. Was driving me crazy. Thanks for saving my sanity. HA!
                – Lee_Str
                Jun 14 '16 at 12:57













              up vote
              1
              down vote










              up vote
              1
              down vote









              Use the below command to set is like in the cpanel.



              export PS1='$(whoami)@${HOSTNAME%%.*} [$(pwd)]# '






              share|improve this answer














              Use the below command to set is like in the cpanel.



              export PS1='$(whoami)@${HOSTNAME%%.*} [$(pwd)]# '







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Oct 21 '15 at 12:39

























              answered Oct 21 '15 at 12:29









              Milan

              312




              312












              • Thanks! None of the other options above worked. This one did. Was driving me crazy. Thanks for saving my sanity. HA!
                – Lee_Str
                Jun 14 '16 at 12:57


















              • Thanks! None of the other options above worked. This one did. Was driving me crazy. Thanks for saving my sanity. HA!
                – Lee_Str
                Jun 14 '16 at 12:57
















              Thanks! None of the other options above worked. This one did. Was driving me crazy. Thanks for saving my sanity. HA!
              – Lee_Str
              Jun 14 '16 at 12:57




              Thanks! None of the other options above worked. This one did. Was driving me crazy. Thanks for saving my sanity. HA!
              – Lee_Str
              Jun 14 '16 at 12:57










              up vote
              0
              down vote













              One might consider to pimp the prompt by adding some colors. For instance:



              export PS1='[e[0;36m]u[e[0m]@[e[0;33m]h[e[0m]:[e[0;35m]w[e[0m]$ '





              share|improve this answer








              New contributor




              Arvid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






















                up vote
                0
                down vote













                One might consider to pimp the prompt by adding some colors. For instance:



                export PS1='[e[0;36m]u[e[0m]@[e[0;33m]h[e[0m]:[e[0;35m]w[e[0m]$ '





                share|improve this answer








                New contributor




                Arvid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.




















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  One might consider to pimp the prompt by adding some colors. For instance:



                  export PS1='[e[0;36m]u[e[0m]@[e[0;33m]h[e[0m]:[e[0;35m]w[e[0m]$ '





                  share|improve this answer








                  New contributor




                  Arvid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  One might consider to pimp the prompt by adding some colors. For instance:



                  export PS1='[e[0;36m]u[e[0m]@[e[0;33m]h[e[0m]:[e[0;35m]w[e[0m]$ '






                  share|improve this answer








                  New contributor




                  Arvid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  share|improve this answer



                  share|improve this answer






                  New contributor




                  Arvid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered Nov 23 at 13:35









                  Arvid

                  1013




                  1013




                  New contributor




                  Arvid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  Arvid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  Arvid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Super User!


                      • 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.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • 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%2fsuperuser.com%2fquestions%2f601181%2fhow-to-display-current-path-in-command-prompt-in-linuxs-sh-not-bash%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

                      If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                      Alcedinidae

                      Can an atomic nucleus contain both particles and antiparticles? [duplicate]