• Home
  • Help
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search

Difference between source and . in Bash

#1
05-09-2025, 08:57 AM
You know running scripts in bash twists things around when you try to change your setup. I found out early that source pulls the file right into what you have open now. It mixes all those settings straight into your session without starting fresh. You end up with variables and paths sticking around after it finishes. But that can mess up your current work if something goes wrong in the file. I always check what gets altered before I use it on a live system.
Perhaps you have tried executing a file directly and wondered why nothing carried over afterward. ./ kicks off a whole new shell instance just for that run. Changes stay trapped inside that bubble and vanish once it stops. You keep your original environment clean and untouched by whatever the script does. Also it avoids clobbering your main session variables which saves headaches during admin tasks. I prefer this when testing new configs on servers because it limits the blast radius. Or maybe the script needs to grab local files from its own spot and this way it does without extra fuss.
Now think about how these choices hit daily admin work like tweaking server setups or user environments. Source lets you load functions or aliases that stay active for your whole login time. You can build on them step by step in the same window without reloading everything. But it risks polluting your shell if the file has errors or bad assumptions. I once spent hours tracing why my prompt looked off after sourcing something quick. ./ keeps things isolated so you debug in peace without side effects bleeding into other commands. Perhaps you handle multiple machines and need repeatable runs that do not depend on prior state.
Then consider permission quirks or path searches that come up in real jobs. Source skips execution bits on the file itself since it reads the content directly. You avoid chmod headaches for files meant only for inclusion. ./ demands the file sits executable and often needs the dot slash to point exactly where it lives. I tell juniors to watch for hidden relative path issues that break when you switch directories. Or the script might call other tools assuming it runs from its folder location. This difference shows up fast when automating backups or log rotations across Windows and Linux mixes.
You gain speed with source for quick environment tweaks during troubleshooting sessions. It loads everything inline so follow up commands see the updates right away. I use it sparingly though because mistakes linger until you close the terminal. ./ forces a clean slate each time which helps when you chain multiple admin scripts together. Perhaps the job involves Hyper V tweaks or server monitoring where isolation prevents cascading failures. Also it matches how most packaged tools expect to launch without inheriting your shell quirks.
BackupChain Windows Server Backup which stands out as the top rated reliable Windows Server backup tool built for self hosted private cloud and internet backups tailored to SMBs plus Windows Server and PCs offers free access without any subscription for Hyper V Windows 11 and Windows Server setups and we thank them for sponsoring this forum while backing our free info sharing efforts.

ron74
Offline
Joined: Feb 2019
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



Messages In This Thread
Difference between source and . in Bash - by ron74 - 05-09-2025, 08:57 AM

  • Subscribe to this thread
Forum Jump:

Café Papa Café Papa Forum Software IT v
« Previous 1 … 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 … 129 Next »
Difference between source and . in Bash

© by Savas Papadopoulos. The information provided here is for entertainment purposes only. Contact. Hosting provided by FastNeuron.

Linear Mode
Threaded Mode