Is it possible to change the PS1 periodically by a script in the background?

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,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I just came across the PS1 variable.
It is possible to change the prompt by simply changing this variables value,
for instance:



PS1="h"
hostname as Prompt
PS1="j"
numbers of current jobs as Prompt
PS1="t"
current time as Prompt
PS!="j running on h :"
or more complex string with many substitutions


Now since there is something like a background process that does not occupy the shell, I thought if it was possible to write a script that changes the value of PS1 each 5 seconds once that could be running whole time in the background.



Pseudo-Script:



Repeat


PS1="j jobs"
sleep 5 seconds
PS1="time: t"
sleep 5 seconds
PS1="Command History: !"
sleep 5 seconds



If it is possible, how would you implement it in bash shell script ?










share|improve this question



















  • 1





    I don't think it is... but just think how irritating that could be?

    – Sobrique
    Mar 31 '15 at 18:23

















1















I just came across the PS1 variable.
It is possible to change the prompt by simply changing this variables value,
for instance:



PS1="h"
hostname as Prompt
PS1="j"
numbers of current jobs as Prompt
PS1="t"
current time as Prompt
PS!="j running on h :"
or more complex string with many substitutions


Now since there is something like a background process that does not occupy the shell, I thought if it was possible to write a script that changes the value of PS1 each 5 seconds once that could be running whole time in the background.



Pseudo-Script:



Repeat


PS1="j jobs"
sleep 5 seconds
PS1="time: t"
sleep 5 seconds
PS1="Command History: !"
sleep 5 seconds



If it is possible, how would you implement it in bash shell script ?










share|improve this question



















  • 1





    I don't think it is... but just think how irritating that could be?

    – Sobrique
    Mar 31 '15 at 18:23













1












1








1


0






I just came across the PS1 variable.
It is possible to change the prompt by simply changing this variables value,
for instance:



PS1="h"
hostname as Prompt
PS1="j"
numbers of current jobs as Prompt
PS1="t"
current time as Prompt
PS!="j running on h :"
or more complex string with many substitutions


Now since there is something like a background process that does not occupy the shell, I thought if it was possible to write a script that changes the value of PS1 each 5 seconds once that could be running whole time in the background.



Pseudo-Script:



Repeat


PS1="j jobs"
sleep 5 seconds
PS1="time: t"
sleep 5 seconds
PS1="Command History: !"
sleep 5 seconds



If it is possible, how would you implement it in bash shell script ?










share|improve this question
















I just came across the PS1 variable.
It is possible to change the prompt by simply changing this variables value,
for instance:



PS1="h"
hostname as Prompt
PS1="j"
numbers of current jobs as Prompt
PS1="t"
current time as Prompt
PS!="j running on h :"
or more complex string with many substitutions


Now since there is something like a background process that does not occupy the shell, I thought if it was possible to write a script that changes the value of PS1 each 5 seconds once that could be running whole time in the background.



Pseudo-Script:



Repeat


PS1="j jobs"
sleep 5 seconds
PS1="time: t"
sleep 5 seconds
PS1="Command History: !"
sleep 5 seconds



If it is possible, how would you implement it in bash shell script ?







shell-script command-line prompt






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 18 at 3:24









Rui F Ribeiro

42.1k1484142




42.1k1484142










asked Mar 31 '15 at 17:37









Abdul Al HazredAbdul Al Hazred

7,742214472




7,742214472







  • 1





    I don't think it is... but just think how irritating that could be?

    – Sobrique
    Mar 31 '15 at 18:23












  • 1





    I don't think it is... but just think how irritating that could be?

    – Sobrique
    Mar 31 '15 at 18:23







1




1





I don't think it is... but just think how irritating that could be?

– Sobrique
Mar 31 '15 at 18:23





I don't think it is... but just think how irritating that could be?

– Sobrique
Mar 31 '15 at 18:23










2 Answers
2






active

oldest

votes


















2














None of the common unix shells (bash, [pd]ksh, [t]csh) have their own, internal analogue to cron in order to do automatic background tasks as you wish.



But even if they did, after you've run a command and it has come back to the prompt, that character output to show the prompt is static, not dynamic. If you sat there and watched, it would not cycle through your PS1 alternatives every 5 seconds like you are thinking. You would not see a new prompt until after you hit enter or ran another command.



However, you might be able to get what you are looking for by using GNU screen which has "taskbar" capabilities. Try starting with this.






share|improve this answer






























    2














    I don't think it is possible, even if you incorporate the above pseudo-code in a shell script, because on each invocation of the shell script, it will start its own sub-shell where this stuff will happen and not where you want it to (your main shell). Even if you start it in the background. (script.sh &)






    share|improve this answer























    • it is not possible to change settings in the shell from the subshell?

      – Abdul Al Hazred
      Mar 31 '15 at 19:47






    • 1





      This is the same reason that a sub-process cannot change it's parent process's working directory. The working directory, like environment variables such as PS1, are part of the process's environment which a child process cannot affect. This is the reason that the cd command must be built into the shell as opposed to being a separate executable.

      – DoxyLover
      Mar 31 '15 at 22:36











    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%2f193635%2fis-it-possible-to-change-the-ps1-periodically-by-a-script-in-the-background%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









    2














    None of the common unix shells (bash, [pd]ksh, [t]csh) have their own, internal analogue to cron in order to do automatic background tasks as you wish.



    But even if they did, after you've run a command and it has come back to the prompt, that character output to show the prompt is static, not dynamic. If you sat there and watched, it would not cycle through your PS1 alternatives every 5 seconds like you are thinking. You would not see a new prompt until after you hit enter or ran another command.



    However, you might be able to get what you are looking for by using GNU screen which has "taskbar" capabilities. Try starting with this.






    share|improve this answer



























      2














      None of the common unix shells (bash, [pd]ksh, [t]csh) have their own, internal analogue to cron in order to do automatic background tasks as you wish.



      But even if they did, after you've run a command and it has come back to the prompt, that character output to show the prompt is static, not dynamic. If you sat there and watched, it would not cycle through your PS1 alternatives every 5 seconds like you are thinking. You would not see a new prompt until after you hit enter or ran another command.



      However, you might be able to get what you are looking for by using GNU screen which has "taskbar" capabilities. Try starting with this.






      share|improve this answer

























        2












        2








        2







        None of the common unix shells (bash, [pd]ksh, [t]csh) have their own, internal analogue to cron in order to do automatic background tasks as you wish.



        But even if they did, after you've run a command and it has come back to the prompt, that character output to show the prompt is static, not dynamic. If you sat there and watched, it would not cycle through your PS1 alternatives every 5 seconds like you are thinking. You would not see a new prompt until after you hit enter or ran another command.



        However, you might be able to get what you are looking for by using GNU screen which has "taskbar" capabilities. Try starting with this.






        share|improve this answer













        None of the common unix shells (bash, [pd]ksh, [t]csh) have their own, internal analogue to cron in order to do automatic background tasks as you wish.



        But even if they did, after you've run a command and it has come back to the prompt, that character output to show the prompt is static, not dynamic. If you sat there and watched, it would not cycle through your PS1 alternatives every 5 seconds like you are thinking. You would not see a new prompt until after you hit enter or ran another command.



        However, you might be able to get what you are looking for by using GNU screen which has "taskbar" capabilities. Try starting with this.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 31 '15 at 18:33









        BytorBytor

        43137




        43137























            2














            I don't think it is possible, even if you incorporate the above pseudo-code in a shell script, because on each invocation of the shell script, it will start its own sub-shell where this stuff will happen and not where you want it to (your main shell). Even if you start it in the background. (script.sh &)






            share|improve this answer























            • it is not possible to change settings in the shell from the subshell?

              – Abdul Al Hazred
              Mar 31 '15 at 19:47






            • 1





              This is the same reason that a sub-process cannot change it's parent process's working directory. The working directory, like environment variables such as PS1, are part of the process's environment which a child process cannot affect. This is the reason that the cd command must be built into the shell as opposed to being a separate executable.

              – DoxyLover
              Mar 31 '15 at 22:36















            2














            I don't think it is possible, even if you incorporate the above pseudo-code in a shell script, because on each invocation of the shell script, it will start its own sub-shell where this stuff will happen and not where you want it to (your main shell). Even if you start it in the background. (script.sh &)






            share|improve this answer























            • it is not possible to change settings in the shell from the subshell?

              – Abdul Al Hazred
              Mar 31 '15 at 19:47






            • 1





              This is the same reason that a sub-process cannot change it's parent process's working directory. The working directory, like environment variables such as PS1, are part of the process's environment which a child process cannot affect. This is the reason that the cd command must be built into the shell as opposed to being a separate executable.

              – DoxyLover
              Mar 31 '15 at 22:36













            2












            2








            2







            I don't think it is possible, even if you incorporate the above pseudo-code in a shell script, because on each invocation of the shell script, it will start its own sub-shell where this stuff will happen and not where you want it to (your main shell). Even if you start it in the background. (script.sh &)






            share|improve this answer













            I don't think it is possible, even if you incorporate the above pseudo-code in a shell script, because on each invocation of the shell script, it will start its own sub-shell where this stuff will happen and not where you want it to (your main shell). Even if you start it in the background. (script.sh &)







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 31 '15 at 18:59









            Nikolai Alexandrov GeorgievNikolai Alexandrov Georgiev

            1313




            1313












            • it is not possible to change settings in the shell from the subshell?

              – Abdul Al Hazred
              Mar 31 '15 at 19:47






            • 1





              This is the same reason that a sub-process cannot change it's parent process's working directory. The working directory, like environment variables such as PS1, are part of the process's environment which a child process cannot affect. This is the reason that the cd command must be built into the shell as opposed to being a separate executable.

              – DoxyLover
              Mar 31 '15 at 22:36

















            • it is not possible to change settings in the shell from the subshell?

              – Abdul Al Hazred
              Mar 31 '15 at 19:47






            • 1





              This is the same reason that a sub-process cannot change it's parent process's working directory. The working directory, like environment variables such as PS1, are part of the process's environment which a child process cannot affect. This is the reason that the cd command must be built into the shell as opposed to being a separate executable.

              – DoxyLover
              Mar 31 '15 at 22:36
















            it is not possible to change settings in the shell from the subshell?

            – Abdul Al Hazred
            Mar 31 '15 at 19:47





            it is not possible to change settings in the shell from the subshell?

            – Abdul Al Hazred
            Mar 31 '15 at 19:47




            1




            1





            This is the same reason that a sub-process cannot change it's parent process's working directory. The working directory, like environment variables such as PS1, are part of the process's environment which a child process cannot affect. This is the reason that the cd command must be built into the shell as opposed to being a separate executable.

            – DoxyLover
            Mar 31 '15 at 22:36





            This is the same reason that a sub-process cannot change it's parent process's working directory. The working directory, like environment variables such as PS1, are part of the process's environment which a child process cannot affect. This is the reason that the cd command must be built into the shell as opposed to being a separate executable.

            – DoxyLover
            Mar 31 '15 at 22:36

















            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%2f193635%2fis-it-possible-to-change-the-ps1-periodically-by-a-script-in-the-background%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 to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay