![]() |
| AutoFolderCopy.sh (code) |
Hello there! I hope everyone’s doing well and staying healthy. Today, I’m presenting a demonstration of AutoFolderCopy.sh, a Bash script that automates copying a list of folders from the current directory to a destination path with its contents and sub folders. This is a real world coding demo that shows how I actually write code, make mistakes, fix typos, and debug along the way.
Alright, let’s get straight to it!
Script Design
![]() |
| The functions |
Since I come from an OOP programming background, I’m used to separating code into classes, methods, and modules. In Bash scripting, however, it’s more procedural, so it only supports functions. To keep things clean and readable, I organize my code into functions instead of writing one big "spaghetti" script.
Header File
![]() |
| Header |
The header contains metadata about the script/code and a short description of what the script/code does. It helps anyone reading the script/code to quickly understand its purpose and usage. It makes the script/code more informative and professional.
Configuration Variables
![]() | |
| Configuration variables |
Configuration variables store the basic settings, data, arrays, or any other values used throughout the script or module.
They help centralize important settings in one place, so when I need to change something, I only update these variables and all related parts of the code follow automatically.
So in other words, it centralizing my variables makes my scripts/codes easier to maintain and reduces the risk of mistakes.
Script Functions
![]() |
| Functions |
I come from an OOP background, so I naturally separate my code into MVC and modular designs. In my workflow, I usually have internal modules (used within the code) and external modules (called from the terminal). You can think of these modules like classes, each holding specific sections of code.
In Bash, however, it’s a procedural language, so it only supports functions. Based on my experience, I design scripts with well structured functions to keep the code organized, readable, and maintainable. Even in a procedural language like Bash, modularizing the code with functions helps prevent "spaghetti" scripts.
- Main execution function: copy_folders_from_list()
- Log writer: write_log()
- Summary section: summary_section()
Executor Function
![]() |
| Executor function |
The executor function runs the main task of the script: moving folders and their contents to the destination directory or disk.
Finally, The End
In the next post, I’ll show you how I write the script in real time. I’ll explain it, walk you through the code, and demonstrate it running successfully.Stay tuned for the next part! Thanks for reading, and have a great day!





