How to produce a PS1 prompt in bash or ksh93 similar to tcshbash equivalent of this use of tcsh “sched” command?Bash overwrites the first line, PS1 bash promptHow can avoid these spurious characters in my bash prompt?Show only current and parent directory in bash promptExecute command within current shell before every promptAlias for “cd” which shows current directory each time I change directories?Parameters in bash $PS1 variableHow do I display only the current directory while using powerline in the terminal prompt.?what shell is used to run a scriptprompt (PS1) doesn't update on bound command

Why is the underscore command _ useful?

How do I check if a string is entirely made of the same substring?

What was Apollo 13's "Little Jolt" after MECO?

Is there metaphorical meaning of "aus der Haft entlassen"?

Retract an already submitted recommendation letter (written for an undergrad student)

Negative Resistance

Why didn't the Space Shuttle bounce back into space as many times as possible so as to lose a lot of kinetic energy up there?

What is the best way to deal with NPC-NPC combat?

How to be good at coming up with counter example in Topology

Find the identical rows in a matrix

Do I need to watch Ant-Man and the Wasp and Captain Marvel before watching Avengers: Endgame?

Combinatorics problem, right solution?

How do I deal with a coworker that keeps asking to make small superficial changes to a report, and it is seriously triggering my anxiety?

Is it acceptable to use working hours to read general interest books?

What does MLD stand for?

Could moose/elk survive in the Amazon forest?

Magical attacks and overcoming damage resistance

Island of Knights, Knaves and Spies

Can someone publish a story that happened to you?

How much of a wave function must reside inside event horizon for it to be consumed by the black hole?

Is there really no use for MD5 anymore?

As an international instructor, should I openly talk about my accent?

Why did C use the -> operator instead of reusing the . operator?

Why do games have consumables?



How to produce a PS1 prompt in bash or ksh93 similar to tcsh


bash equivalent of this use of tcsh “sched” command?Bash overwrites the first line, PS1 bash promptHow can avoid these spurious characters in my bash prompt?Show only current and parent directory in bash promptExecute command within current shell before every promptAlias for “cd” which shows current directory each time I change directories?Parameters in bash $PS1 variableHow do I display only the current directory while using powerline in the terminal prompt.?what shell is used to run a scriptprompt (PS1) doesn't update on bound command






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








6















In tcsh, I have the default:



prompt [%m:%c3] %n%# 


which gives prompts like:



[woehler:hacking/c/hello] ajcarr% 


and



[woehler:~] ajcarr% 


In other words, the current directory and up to the next two above it in the path.



In ksh93 or bash, the substitution of $HOME by ~ is easy, as is extracting the name of just the current directory, but I have yet to find a way of replicating the %c3 behaviour of tcsh. At present in ksh93 I have:



[ajcarr@Woehler] hello $ 


and



[ajcarr@Woehler] ~ $ 


Does anyone have any suggestions about how to do this?










share|improve this question






























    6















    In tcsh, I have the default:



    prompt [%m:%c3] %n%# 


    which gives prompts like:



    [woehler:hacking/c/hello] ajcarr% 


    and



    [woehler:~] ajcarr% 


    In other words, the current directory and up to the next two above it in the path.



    In ksh93 or bash, the substitution of $HOME by ~ is easy, as is extracting the name of just the current directory, but I have yet to find a way of replicating the %c3 behaviour of tcsh. At present in ksh93 I have:



    [ajcarr@Woehler] hello $ 


    and



    [ajcarr@Woehler] ~ $ 


    Does anyone have any suggestions about how to do this?










    share|improve this question


























      6












      6








      6


      0






      In tcsh, I have the default:



      prompt [%m:%c3] %n%# 


      which gives prompts like:



      [woehler:hacking/c/hello] ajcarr% 


      and



      [woehler:~] ajcarr% 


      In other words, the current directory and up to the next two above it in the path.



      In ksh93 or bash, the substitution of $HOME by ~ is easy, as is extracting the name of just the current directory, but I have yet to find a way of replicating the %c3 behaviour of tcsh. At present in ksh93 I have:



      [ajcarr@Woehler] hello $ 


      and



      [ajcarr@Woehler] ~ $ 


      Does anyone have any suggestions about how to do this?










      share|improve this question
















      In tcsh, I have the default:



      prompt [%m:%c3] %n%# 


      which gives prompts like:



      [woehler:hacking/c/hello] ajcarr% 


      and



      [woehler:~] ajcarr% 


      In other words, the current directory and up to the next two above it in the path.



      In ksh93 or bash, the substitution of $HOME by ~ is easy, as is extracting the name of just the current directory, but I have yet to find a way of replicating the %c3 behaviour of tcsh. At present in ksh93 I have:



      [ajcarr@Woehler] hello $ 


      and



      [ajcarr@Woehler] ~ $ 


      Does anyone have any suggestions about how to do this?







      bash ksh prompt tcsh






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 23 at 0:48









      steeldriver

      38.2k45489




      38.2k45489










      asked Apr 23 at 0:21









      Alun CarrAlun Carr

      9112




      9112




















          2 Answers
          2






          active

          oldest

          votes


















          7














          In ksh93:



          PS1='$PWD#$PWD%?/*/*/*?/ $ '
          share/doc/libnl-3-dev $ _

          PS1='[$HOSTNAME%%.*:$PWD#$PWD%?/*/*/*?/] $USER% '
          [host:share/doc/libnl-3-dev] user% _


          If you want it to also replace $HOME with ~, something nastier is needed:



          PS1='$(d=$PWD/#$HOME/"~";printf %s "$d#$d%?/*/*/*?/") $ '
          ~/w/maemo $ cd sb2-pathmaps
          w/maemo/sb2-pathmaps $ _

          PS1='$(d=$PWD/#$HOME/"~";printf %s "[$HOSTNAME%%.*:$d#$d%?/*/*/*?/]") $USER% '
          [host:w/maemo/sb2-pathmaps] user% _



          All this should also work in bash, though bash has its own prompt escapes (eg. h for $HOSTNAME%%.*) and path shortening mechanism (with PROMPT_DIRTRIM).



          Also, the nastier variant will be really nasty, because bash, unlike ksh93, will fork() a separate process for each $(...; printf ...) command substitution, even if it contains only builtins. This also holds true for pdksh derived shells, like mksh.




          zsh has prompt escapes quite similar but not identical to tcsh:



          zsh$ PS1='[%m:%3c] %n%# '
          [host:share/doc/libnl-3-dev] user% _



          Note:



          The $HOSTNAME variable is not set by default in ksh93; instead of it you could use the uname builtin (after enabling it with PATH=/opt/ast/bin:$PATH; the /opt/ast/bin path doesn't need to exist):



          PS1='$(d=$PWD/#$HOME/"~";h=$(uname -n); printf %s "[$h%%.*:$d#$d%?/*/*/*?/]") $USER% '


          Unlike the h escape in bash or %m escape in zsh or tcsh this will track the hostname changes.






          share|improve this answer
































            6














            For bash, you could achieve similar results by setting the PROMPT_DIRTRIM variable:



            $ PS1='[u@h] w$ '
            [schaller@r2d2] ~$ pwd
            /home/schaller
            [schaller@r2d2] ~$ PROMPT_DIRTRIM=3
            [schaller@r2d2] ~$ cd /home/schaller/tmp/513924/another/directory/here
            [schaller@r2d2] ~/.../another/directory/here$





            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%2f513924%2fhow-to-produce-a-ps1-prompt-in-bash-or-ksh93-similar-to-tcsh%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









              7














              In ksh93:



              PS1='$PWD#$PWD%?/*/*/*?/ $ '
              share/doc/libnl-3-dev $ _

              PS1='[$HOSTNAME%%.*:$PWD#$PWD%?/*/*/*?/] $USER% '
              [host:share/doc/libnl-3-dev] user% _


              If you want it to also replace $HOME with ~, something nastier is needed:



              PS1='$(d=$PWD/#$HOME/"~";printf %s "$d#$d%?/*/*/*?/") $ '
              ~/w/maemo $ cd sb2-pathmaps
              w/maemo/sb2-pathmaps $ _

              PS1='$(d=$PWD/#$HOME/"~";printf %s "[$HOSTNAME%%.*:$d#$d%?/*/*/*?/]") $USER% '
              [host:w/maemo/sb2-pathmaps] user% _



              All this should also work in bash, though bash has its own prompt escapes (eg. h for $HOSTNAME%%.*) and path shortening mechanism (with PROMPT_DIRTRIM).



              Also, the nastier variant will be really nasty, because bash, unlike ksh93, will fork() a separate process for each $(...; printf ...) command substitution, even if it contains only builtins. This also holds true for pdksh derived shells, like mksh.




              zsh has prompt escapes quite similar but not identical to tcsh:



              zsh$ PS1='[%m:%3c] %n%# '
              [host:share/doc/libnl-3-dev] user% _



              Note:



              The $HOSTNAME variable is not set by default in ksh93; instead of it you could use the uname builtin (after enabling it with PATH=/opt/ast/bin:$PATH; the /opt/ast/bin path doesn't need to exist):



              PS1='$(d=$PWD/#$HOME/"~";h=$(uname -n); printf %s "[$h%%.*:$d#$d%?/*/*/*?/]") $USER% '


              Unlike the h escape in bash or %m escape in zsh or tcsh this will track the hostname changes.






              share|improve this answer





























                7














                In ksh93:



                PS1='$PWD#$PWD%?/*/*/*?/ $ '
                share/doc/libnl-3-dev $ _

                PS1='[$HOSTNAME%%.*:$PWD#$PWD%?/*/*/*?/] $USER% '
                [host:share/doc/libnl-3-dev] user% _


                If you want it to also replace $HOME with ~, something nastier is needed:



                PS1='$(d=$PWD/#$HOME/"~";printf %s "$d#$d%?/*/*/*?/") $ '
                ~/w/maemo $ cd sb2-pathmaps
                w/maemo/sb2-pathmaps $ _

                PS1='$(d=$PWD/#$HOME/"~";printf %s "[$HOSTNAME%%.*:$d#$d%?/*/*/*?/]") $USER% '
                [host:w/maemo/sb2-pathmaps] user% _



                All this should also work in bash, though bash has its own prompt escapes (eg. h for $HOSTNAME%%.*) and path shortening mechanism (with PROMPT_DIRTRIM).



                Also, the nastier variant will be really nasty, because bash, unlike ksh93, will fork() a separate process for each $(...; printf ...) command substitution, even if it contains only builtins. This also holds true for pdksh derived shells, like mksh.




                zsh has prompt escapes quite similar but not identical to tcsh:



                zsh$ PS1='[%m:%3c] %n%# '
                [host:share/doc/libnl-3-dev] user% _



                Note:



                The $HOSTNAME variable is not set by default in ksh93; instead of it you could use the uname builtin (after enabling it with PATH=/opt/ast/bin:$PATH; the /opt/ast/bin path doesn't need to exist):



                PS1='$(d=$PWD/#$HOME/"~";h=$(uname -n); printf %s "[$h%%.*:$d#$d%?/*/*/*?/]") $USER% '


                Unlike the h escape in bash or %m escape in zsh or tcsh this will track the hostname changes.






                share|improve this answer



























                  7












                  7








                  7







                  In ksh93:



                  PS1='$PWD#$PWD%?/*/*/*?/ $ '
                  share/doc/libnl-3-dev $ _

                  PS1='[$HOSTNAME%%.*:$PWD#$PWD%?/*/*/*?/] $USER% '
                  [host:share/doc/libnl-3-dev] user% _


                  If you want it to also replace $HOME with ~, something nastier is needed:



                  PS1='$(d=$PWD/#$HOME/"~";printf %s "$d#$d%?/*/*/*?/") $ '
                  ~/w/maemo $ cd sb2-pathmaps
                  w/maemo/sb2-pathmaps $ _

                  PS1='$(d=$PWD/#$HOME/"~";printf %s "[$HOSTNAME%%.*:$d#$d%?/*/*/*?/]") $USER% '
                  [host:w/maemo/sb2-pathmaps] user% _



                  All this should also work in bash, though bash has its own prompt escapes (eg. h for $HOSTNAME%%.*) and path shortening mechanism (with PROMPT_DIRTRIM).



                  Also, the nastier variant will be really nasty, because bash, unlike ksh93, will fork() a separate process for each $(...; printf ...) command substitution, even if it contains only builtins. This also holds true for pdksh derived shells, like mksh.




                  zsh has prompt escapes quite similar but not identical to tcsh:



                  zsh$ PS1='[%m:%3c] %n%# '
                  [host:share/doc/libnl-3-dev] user% _



                  Note:



                  The $HOSTNAME variable is not set by default in ksh93; instead of it you could use the uname builtin (after enabling it with PATH=/opt/ast/bin:$PATH; the /opt/ast/bin path doesn't need to exist):



                  PS1='$(d=$PWD/#$HOME/"~";h=$(uname -n); printf %s "[$h%%.*:$d#$d%?/*/*/*?/]") $USER% '


                  Unlike the h escape in bash or %m escape in zsh or tcsh this will track the hostname changes.






                  share|improve this answer















                  In ksh93:



                  PS1='$PWD#$PWD%?/*/*/*?/ $ '
                  share/doc/libnl-3-dev $ _

                  PS1='[$HOSTNAME%%.*:$PWD#$PWD%?/*/*/*?/] $USER% '
                  [host:share/doc/libnl-3-dev] user% _


                  If you want it to also replace $HOME with ~, something nastier is needed:



                  PS1='$(d=$PWD/#$HOME/"~";printf %s "$d#$d%?/*/*/*?/") $ '
                  ~/w/maemo $ cd sb2-pathmaps
                  w/maemo/sb2-pathmaps $ _

                  PS1='$(d=$PWD/#$HOME/"~";printf %s "[$HOSTNAME%%.*:$d#$d%?/*/*/*?/]") $USER% '
                  [host:w/maemo/sb2-pathmaps] user% _



                  All this should also work in bash, though bash has its own prompt escapes (eg. h for $HOSTNAME%%.*) and path shortening mechanism (with PROMPT_DIRTRIM).



                  Also, the nastier variant will be really nasty, because bash, unlike ksh93, will fork() a separate process for each $(...; printf ...) command substitution, even if it contains only builtins. This also holds true for pdksh derived shells, like mksh.




                  zsh has prompt escapes quite similar but not identical to tcsh:



                  zsh$ PS1='[%m:%3c] %n%# '
                  [host:share/doc/libnl-3-dev] user% _



                  Note:



                  The $HOSTNAME variable is not set by default in ksh93; instead of it you could use the uname builtin (after enabling it with PATH=/opt/ast/bin:$PATH; the /opt/ast/bin path doesn't need to exist):



                  PS1='$(d=$PWD/#$HOME/"~";h=$(uname -n); printf %s "[$h%%.*:$d#$d%?/*/*/*?/]") $USER% '


                  Unlike the h escape in bash or %m escape in zsh or tcsh this will track the hostname changes.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited yesterday

























                  answered Apr 23 at 1:16









                  mosvymosvy

                  10.8k11338




                  10.8k11338























                      6














                      For bash, you could achieve similar results by setting the PROMPT_DIRTRIM variable:



                      $ PS1='[u@h] w$ '
                      [schaller@r2d2] ~$ pwd
                      /home/schaller
                      [schaller@r2d2] ~$ PROMPT_DIRTRIM=3
                      [schaller@r2d2] ~$ cd /home/schaller/tmp/513924/another/directory/here
                      [schaller@r2d2] ~/.../another/directory/here$





                      share|improve this answer



























                        6














                        For bash, you could achieve similar results by setting the PROMPT_DIRTRIM variable:



                        $ PS1='[u@h] w$ '
                        [schaller@r2d2] ~$ pwd
                        /home/schaller
                        [schaller@r2d2] ~$ PROMPT_DIRTRIM=3
                        [schaller@r2d2] ~$ cd /home/schaller/tmp/513924/another/directory/here
                        [schaller@r2d2] ~/.../another/directory/here$





                        share|improve this answer

























                          6












                          6








                          6







                          For bash, you could achieve similar results by setting the PROMPT_DIRTRIM variable:



                          $ PS1='[u@h] w$ '
                          [schaller@r2d2] ~$ pwd
                          /home/schaller
                          [schaller@r2d2] ~$ PROMPT_DIRTRIM=3
                          [schaller@r2d2] ~$ cd /home/schaller/tmp/513924/another/directory/here
                          [schaller@r2d2] ~/.../another/directory/here$





                          share|improve this answer













                          For bash, you could achieve similar results by setting the PROMPT_DIRTRIM variable:



                          $ PS1='[u@h] w$ '
                          [schaller@r2d2] ~$ pwd
                          /home/schaller
                          [schaller@r2d2] ~$ PROMPT_DIRTRIM=3
                          [schaller@r2d2] ~$ cd /home/schaller/tmp/513924/another/directory/here
                          [schaller@r2d2] ~/.../another/directory/here$






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Apr 23 at 1:16









                          Jeff SchallerJeff Schaller

                          45.4k1164147




                          45.4k1164147



























                              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%2f513924%2fhow-to-produce-a-ps1-prompt-in-bash-or-ksh93-similar-to-tcsh%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 does Billy Russo acquire his 'Jigsaw' mask? Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Favourite questions and answers from the 1st quarter of 2019Why does Bane wear the mask?Why does Kylo Ren wear a mask?Why did Captain America remove his mask while fighting Batroc the Leaper?How did the OA acquire her wisdom?Is Billy Breckenridge gay?How does Adrian Toomes hide his earnings from the IRS?What is the state of affairs on Nootka Sound by the end of season 1?How did Tia Dalma acquire Captain Barbossa's body?How is one “Deemed Worthy”, to acquire the Greatsword “Dawn”?How did Karen acquire the handgun?

                              Личност Атрибути на личността | Литература и източници | НавигацияРаждането на личносттаредактиратередактирате

                              A sequel to Domino's tragic life Why Christmas is for Friends Cold comfort at Charles' padSad farewell for Lady JanePS Most watched News videos