Skip to content

Add shell bundler #41

@eonist

Description

@eonist

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 source statements and inlining the referenced files
  • awk/sed concatenation - Simple approach where you concatenate files and strip duplicate shebangs

Common Approaches

  1. Using source at runtime - The traditional method is to use source or . to include other scripts, but this requires all files to be present at runtime[3]

  2. Manual concatenation with preprocessing - You can write a simple build script that:

    • Reads your main script
    • Finds source statements
    • Replaces them with the actual file contents
    • Outputs a single combined file
  3. SHC (Shell Compiler) - This compiles shell scripts into binaries rather than combining them into one .sh file, 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.sh

For 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]

1
2
3
4
5
6
7
8
9
10
11
12

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions