-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Yes, there are several tools designed to bundle multiple .sh files into a single shell script. Here are the main options:
Dedicated Bundlers
- bash-bundler / bashpack - Tools that combine multiple shell scripts into one, resolving
sourcestatements and inlining the referenced files - awk/sed concatenation - Simple approach where you concatenate files and strip duplicate shebangs
Common Approaches
-
Using
sourceat runtime - The traditional method is to usesourceor.to include other scripts, but this requires all files to be present at runtime[3] -
Manual concatenation with preprocessing - You can write a simple build script that:
- Reads your main script
- Finds
sourcestatements - Replaces them with the actual file contents
- Outputs a single combined file
-
SHC (Shell Compiler) - This compiles shell scripts into binaries rather than combining them into one
.shfile, so it's not exactly what you're looking for[6]
Simple DIY Solution
A basic approach is to create a build script like this:
#!/bin/bash
# build.sh
cat lib/*.sh main.sh > dist/combined.sh
chmod +x dist/combined.shFor more sophisticated needs where you want to resolve source statements automatically, tools like bashcompile or writing a custom preprocessor script that inlines sourced files is the typical solution. The shell scripting ecosystem doesn't have a standardized "bundler" like JavaScript has with webpack, so many developers create project-specific build scripts for this purpose.[5]