Keep file data always available to Bash, without repeated execution (also after reboot)

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have a file named ~/myScripts/assignments.sh which contains various assignments such as variables and aliases. Here's a taste from that file:



drt="/var/www/html"
rss="/etc/init.d/php*-fpm restart && systemctl restart nginx.service"

alias drt="cd $drt"
alias rss="$rss"


I use these assignments frequently from the moment I finished installing my operating system, especially to write neater scripts for installation, configuration and maintenance of my webserver and adjacent software.



Thus, it's vital that this file will always be exported, that its data will always be available in all Bash sessions, immediately after any Bash session has started (also after a reboot).



To achieve that, I thought of the following lousy script:



source ~/myScripts/assignments.sh # Immediate availability;
printf "n%s" "source ~/myScripts/assignments.sh" >> ~/.profile
cat > "cron_daily.sh" <<< "source ~/myScripts/assignments.sh"

crontab <<-"CRONTAB"
0 0 * * * ~/myScripts/cron_daily.sh # Permanent availability (after the one minute gap);
CRONTAB


What will be a good approach to achieve the state I described above?



Update



The reason I'd think to avoid sourcing the file, then add source ~/myScripts/assignments.sh inside bash.bashrc is that I've seen some devops reluctant from sourcing bash.bashrc in general. Although, when the file isn't customized, or has just such small change it is generally not a problem.







share|improve this question


























    up vote
    0
    down vote

    favorite












    I have a file named ~/myScripts/assignments.sh which contains various assignments such as variables and aliases. Here's a taste from that file:



    drt="/var/www/html"
    rss="/etc/init.d/php*-fpm restart && systemctl restart nginx.service"

    alias drt="cd $drt"
    alias rss="$rss"


    I use these assignments frequently from the moment I finished installing my operating system, especially to write neater scripts for installation, configuration and maintenance of my webserver and adjacent software.



    Thus, it's vital that this file will always be exported, that its data will always be available in all Bash sessions, immediately after any Bash session has started (also after a reboot).



    To achieve that, I thought of the following lousy script:



    source ~/myScripts/assignments.sh # Immediate availability;
    printf "n%s" "source ~/myScripts/assignments.sh" >> ~/.profile
    cat > "cron_daily.sh" <<< "source ~/myScripts/assignments.sh"

    crontab <<-"CRONTAB"
    0 0 * * * ~/myScripts/cron_daily.sh # Permanent availability (after the one minute gap);
    CRONTAB


    What will be a good approach to achieve the state I described above?



    Update



    The reason I'd think to avoid sourcing the file, then add source ~/myScripts/assignments.sh inside bash.bashrc is that I've seen some devops reluctant from sourcing bash.bashrc in general. Although, when the file isn't customized, or has just such small change it is generally not a problem.







    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a file named ~/myScripts/assignments.sh which contains various assignments such as variables and aliases. Here's a taste from that file:



      drt="/var/www/html"
      rss="/etc/init.d/php*-fpm restart && systemctl restart nginx.service"

      alias drt="cd $drt"
      alias rss="$rss"


      I use these assignments frequently from the moment I finished installing my operating system, especially to write neater scripts for installation, configuration and maintenance of my webserver and adjacent software.



      Thus, it's vital that this file will always be exported, that its data will always be available in all Bash sessions, immediately after any Bash session has started (also after a reboot).



      To achieve that, I thought of the following lousy script:



      source ~/myScripts/assignments.sh # Immediate availability;
      printf "n%s" "source ~/myScripts/assignments.sh" >> ~/.profile
      cat > "cron_daily.sh" <<< "source ~/myScripts/assignments.sh"

      crontab <<-"CRONTAB"
      0 0 * * * ~/myScripts/cron_daily.sh # Permanent availability (after the one minute gap);
      CRONTAB


      What will be a good approach to achieve the state I described above?



      Update



      The reason I'd think to avoid sourcing the file, then add source ~/myScripts/assignments.sh inside bash.bashrc is that I've seen some devops reluctant from sourcing bash.bashrc in general. Although, when the file isn't customized, or has just such small change it is generally not a problem.







      share|improve this question














      I have a file named ~/myScripts/assignments.sh which contains various assignments such as variables and aliases. Here's a taste from that file:



      drt="/var/www/html"
      rss="/etc/init.d/php*-fpm restart && systemctl restart nginx.service"

      alias drt="cd $drt"
      alias rss="$rss"


      I use these assignments frequently from the moment I finished installing my operating system, especially to write neater scripts for installation, configuration and maintenance of my webserver and adjacent software.



      Thus, it's vital that this file will always be exported, that its data will always be available in all Bash sessions, immediately after any Bash session has started (also after a reboot).



      To achieve that, I thought of the following lousy script:



      source ~/myScripts/assignments.sh # Immediate availability;
      printf "n%s" "source ~/myScripts/assignments.sh" >> ~/.profile
      cat > "cron_daily.sh" <<< "source ~/myScripts/assignments.sh"

      crontab <<-"CRONTAB"
      0 0 * * * ~/myScripts/cron_daily.sh # Permanent availability (after the one minute gap);
      CRONTAB


      What will be a good approach to achieve the state I described above?



      Update



      The reason I'd think to avoid sourcing the file, then add source ~/myScripts/assignments.sh inside bash.bashrc is that I've seen some devops reluctant from sourcing bash.bashrc in general. Although, when the file isn't customized, or has just such small change it is generally not a problem.









      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 9 at 7:30

























      asked Feb 8 at 8:58









      user9303970

      123224




      123224




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          7
          down vote



          accepted










          If the assignments are necessary for "all" bash-sessions, simply put the file in somewhere like /etc/assignments and source it globally from /etc/bash.bashrc.



          Append this into /etc/bash.bashrc:



          source /etc/assignments


          That way, you have all your definitions available in all bash-sessions, for every user, and can maintain the information in a separate file.






          share|improve this answer






















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );








             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f422745%2fkeep-file-data-always-available-to-bash-without-repeated-execution-also-after%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            7
            down vote



            accepted










            If the assignments are necessary for "all" bash-sessions, simply put the file in somewhere like /etc/assignments and source it globally from /etc/bash.bashrc.



            Append this into /etc/bash.bashrc:



            source /etc/assignments


            That way, you have all your definitions available in all bash-sessions, for every user, and can maintain the information in a separate file.






            share|improve this answer


























              up vote
              7
              down vote



              accepted










              If the assignments are necessary for "all" bash-sessions, simply put the file in somewhere like /etc/assignments and source it globally from /etc/bash.bashrc.



              Append this into /etc/bash.bashrc:



              source /etc/assignments


              That way, you have all your definitions available in all bash-sessions, for every user, and can maintain the information in a separate file.






              share|improve this answer
























                up vote
                7
                down vote



                accepted







                up vote
                7
                down vote



                accepted






                If the assignments are necessary for "all" bash-sessions, simply put the file in somewhere like /etc/assignments and source it globally from /etc/bash.bashrc.



                Append this into /etc/bash.bashrc:



                source /etc/assignments


                That way, you have all your definitions available in all bash-sessions, for every user, and can maintain the information in a separate file.






                share|improve this answer














                If the assignments are necessary for "all" bash-sessions, simply put the file in somewhere like /etc/assignments and source it globally from /etc/bash.bashrc.



                Append this into /etc/bash.bashrc:



                source /etc/assignments


                That way, you have all your definitions available in all bash-sessions, for every user, and can maintain the information in a separate file.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Feb 9 at 21:20









                Jeff Schaller

                31.3k846105




                31.3k846105










                answered Feb 8 at 9:57









                Stefan M

                8101617




                8101617






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f422745%2fkeep-file-data-always-available-to-bash-without-repeated-execution-also-after%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?