How to produce a PS1 prompt in bash or ksh93 similar to tcsh Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) 2019 Community Moderator Election Results Why I closed the “Why is Kali so hard” questionbash 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 are two-digit numbers in Jonathan Swift's "Gulliver's Travels" (1726) written in "German style"?

Why do people think Winterfell crypts is the safest place for women, children & old people?

Unix AIX passing variable and arguments to expect and spawn

Pointing to problems without suggesting solutions

How to break 信じようとしていただけかも知れない into separate parts?

Normal Operator || T^2|| = ||T||^2

Sorting the characters in a utf-16 string in java

Why isn't everyone flabbergasted about Bran's "gift"?

Can I ask an author to send me his ebook?

Putting Ant-Man on house arrest

Can I take recommendation from someone I met at a conference?

Knights and Knaves question

Does traveling In The United States require a passport or can I use my green card if not a US citizen?

What documents does someone with a long-term visa need to travel to another Schengen country?

Is there a verb for listening stealthily?

Why does BitLocker not use RSA?

Is Bran literally the world's memory?

Construct a nonabelian group of order 44

How to create a command for the "strange m" symbol in latex?

Raising a bilingual kid. When should we introduce the majority language?

Is it OK if I do not take the receipt in Germany?

How to mute a string and play another at the same time

lm and glm function in R

A journey... into the MIND



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



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionbash 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;








3















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






























    3















    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


























      3












      3








      3


      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 4 hours ago









      steeldriver

      38.1k45489




      38.1k45489










      asked 4 hours ago









      Alun CarrAlun Carr

      7612




      7612




















          2 Answers
          2






          active

          oldest

          votes


















          3














          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






























            2














            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% _





            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









              3














              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



























                3














                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

























                  3












                  3








                  3







                  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 3 hours ago









                  Jeff SchallerJeff Schaller

                  45.2k1164147




                  45.2k1164147























                      2














                      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% _





                      share|improve this answer





























                        2














                        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% _





                        share|improve this answer



























                          2












                          2








                          2







                          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% _





                          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% _






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited 1 hour ago

























                          answered 3 hours ago









                          mosvymosvy

                          10.6k11338




                          10.6k11338



























                              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

                              Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                              Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                              Ласкавець круглолистий Зміст Опис | Поширення | Галерея | Примітки | Посилання | Навігаційне меню58171138361-22960890446Bupleurum rotundifoliumEuro+Med PlantbasePlants of the World Online — Kew ScienceGermplasm Resources Information Network (GRIN)Ласкавецькн. VI : Літери Ком — Левиправивши або дописавши її