PageSourceSearch

https://dillionmegida.com/component---src-components-blog-post-ful…ion-files-index-mdx-cd4ceb1cecddd662aa0d.js

js dillionmegida.com collected 2026-10-03 22:46:54 UTC 5,389 bytes, 2 lines download raw bytes

1"use strict";(self.webpackChunkdillionmegida_com=self.webpackChunkdillionmegida_com||[]).push([[21],{6176:function(e,n,t){t.r(n),t.d(n,{default:function(){return s}});var l=t(8453),a=t(6540);function r(e){const n=Object.assign({p:"p",a:"a",code:"code",h2:"h2",ul:"ul",li:"li",pre:"pre",strong:"strong"},(0,l.RP)(),e.components);return a.createElement(a.Fragment,null,a.createElement(n.p,null,"In ",a.createElement(n.a,{href:"/p/sourcing-vs-executing-script-directly"},"my previous article"),", I explained the difference between ",a.createElement(n.code,null,"source"),"ing and executing a script directly. That article led to this question I'm answering in this article."),"\n",a.createElement(n.p,null,"If you've used shell configuration files like ",a.createElement(n.code,null,".bashrc")," or ",a.createElement(n.code,null,".zshrc")," before, you'd notice that often times you're instructed to do ",a.createElement(n.code,null,"source .bashrc")," or ",a.createElement(n.code,null,"source .zshrc")," when you make changes to these files. Why do you have to do this?"),"\n",a.createElement(n.h2,null,"Configuration files run at the beginning of a terminal session"),"\n",a.createElement(n.p,null,"Say you're using ",a.createElement(n.code,null,"bash")," for your terminal; the first time you open a terminal, ",a.createElement(n.code,null,".bashrc")," is read:"),"\n",a.createElement(n.ul,null,"\n",a.createElement(n.li,null,"the code in that file even those that you added will be run"),"\n",a.createElement(n.li,null,"variables and functions from that file are exposed and accessible in your terminal"),"\n",a.createElement(n.li,null,"then you can begin using the terminal"),"\n"),"\n",a.createElement(n.p,null,"The same principle applies if you're using ",a.createElement(n.code,null,"zsh"),". In that case, it reads from ",a.createElement(n.code,null,".zshrc"),"."),"\n",a.createElement(n.p,null,"You can actually try this by adding an ",a.createElement(n.code,null,'echo "hello world"')," in such file:"),"\n",a.createElement(n.pre,null,a.createElement(n.code,{className:"language-bash"},'filename=.bashrc / .zshrc\n# some stuff here\n\necho "hello world"\n')),"\n",a.createElement(n.p,null,"Then create a new terminal shell, and you would see:"),"\n",a.createElement(n.pre,null,a.createElement(n.code,{className:"language-bash"},"hello world\n")),"\n",a.createElement(n.p,null,"You can create any variable here. Often times, people add ",a.createElement(n.code,null,"PATH")," here so they can use it in their terminal with other commands."),"\n",a.createElement(n.h2,null,"What happens when you make changes to this file?"),"\n",a.createElement(n.p,null,"When you make changes to that configuration file, those changes would not reflect in your current terminal session. Remember ",a.createElement(n.strong,null,"that file only ran at the beginning"),"."),"\n",a.createElement(n.p,null,'The new changes (for example, declared variables) would only reflect in a "new" terminal session. So you would have to close the current session, then create a new one which would include the updated changes from the configuration file.'),"\n",a.createElement(n.p,null,"What if you make another change to the configuration file? Uhmmmm...you need to create a new session to access those changes."),"\n",a.createElement(n.p,null,"Closing and opening a new session all the time might not be the most convenient"),"\n",a.createElement(n.p,null,"And this is where you ",a.createElement(n.code,null,"source"),"."),"\n",a.createElement(n.h2,null,"Sourcing configuration files"),"\n",a.createElement(n.p,null,"By doing the following in your current terminal session:"),"\n",a.createElement(n.pre,null,a.createElement(n.code,{className:"language-bash"},"source .bashrc\n")),"\n",a.createElement(n.p,null,'You are "reading" (executing) the configuration file ',a.createElement(n.strong,null,"again"),". Note that the configuration file is actually a script. And by using ",a.createElement(n.code,null,"source"),", that execution takes place ",a.createElement(n.strong,null,"in the current shell")," (the current process). This way, any variables and functions you have there, becomes available in the current session."),"\n",a.createElement(n.p,null,"No need to open another terminal session. You can carry on in the same terminal session with access to the updated configuration file."),"\n",a.createElement(n.h2,null,"Wrap up"),"\n",a.createElement(n.p,null,"So, you don't always need to ",a.createElement(n.code,null,"source ...")," configuration files. The terminal already does that at the beginning of a session. If you want access to the updated configuration, you can create a new session."),"\n",a.createElement(n.p,null,"But, if you want access to the updated configuration in the same terminal session, then ",a.createElement(n.code,null,"source")," is a friendly tool for that purpose."),"\n")}var o=function(e){void 0===e&&(e={});const{wrapper:n}=Object.assign({},(0,l.RP)(),e.components);return n?a.createElement(n,e,a.createElement(r,e)):r(e)},c=t(8094);function i(e){let{data:n,children:t}=e;const l=n.mdx;return a.createElement(c.A,{post:l},t)}function s(e){return a.createElement(i,e,a.createElement(o,e))}}}]);
2//# sourceMappingURL=component---src-components-blog-post-full-mdx-tsx-content-file-path-data-articles-115-sourcing-configuration-files-index-mdx-cd4ceb1cecddd662aa0d.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.