Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dodie/bash-preprocessor
Bash Macros: replace snippets in a script file with their output
https://github.com/dodie/bash-preprocessor
bash preprocessor
Last synced: 3 months ago
JSON representation
Bash Macros: replace snippets in a script file with their output
- Host: GitHub
- URL: https://github.com/dodie/bash-preprocessor
- Owner: dodie
- License: mit
- Created: 2020-06-28T14:03:11.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-06-29T17:34:43.000Z (over 4 years ago)
- Last Synced: 2024-05-15T13:40:51.578Z (6 months ago)
- Topics: bash, preprocessor
- Language: Shell
- Homepage:
- Size: 6.84 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Bash Preprocessor: replace snippets with their output
## Example: bake timestamp or version
```bash
#!/bin/bash@@@START@@@
echo "# Build date: $(date)"
@@@END@@@echo "Hello World!"
```By running the preprocessor on this file, the code between `@@@START@@@` and `@@@END@@@` will be executed and replaced by its output.
```bash
#!/bin/bash# Build date: Sun Jun 28 15:31:07 CEST 2020
echo "Hello World!"
```## Example: statically import a file
Stuff can be imported from other scripts at runtime using `source`, but sometimes a self-contained script is better.
```bash
#!/bin/bash@@@START@@@
cat another-script-file.sh
@@@END@@@echo "Hello World!"
```In this case, the resulting script file will contain everything from the other script file as well.
## Usage
1. Get `preprocess.sh`:
- grab and extract a [release](https://github.com/dodie/bash-preprocessor/releases)
- clone this repository
- simply copy `preprocess.sh`2. Run the script to preprocess a file (it will change its contents in place):
```
./preprocess.sh
```If needed the `@@@START@@@` and `@@@END@@@` tokens can be customized with an optional 2nd and 3rd argument:
```
./preprocess.sh "" ""
```