Bash-minifier
September 6, 2026 · View on GitHub
A bash script used to minify other bash scripts.
This script will attempt convert any bash script to a one liner (or two lines if counting the shebang) using a state aware parser. This is not always possible for a valid bash syntax, for example with heredocs, which will be left in place.
Usage
Example usage:
./bash-minifier.sh -f="$HOME/Desktop/test.sh"
This will minify a script named "test.sh" on the desktop and output its content to stdout.
./bash-minifier.sh -f="$HOME/Desktop/test.sh" -o="$HOME/Desktop/output.sh"
This will do the same, but will write the output to a file named "output.sh", and give it execution permissions(due to default settings not overrun), on the users desktop.
./bash-minifier.sh < $HOME/Desktop/test.sh > $HOME/Desktop/output.sh
This will read from STDIN and write to STDOUT; because of the redirection,
this works the same way as the previous example.
./bash-minifier.sh -F -f="$HOME/Desktop/test.sh" -o="$HOME/Desktop/output.sh" -p=u-r
This will minify and write the script to desktop, and remove read access for the current user from it.
Supported options
File
-f or --file
Requires a parameter
This option chooses what file to read from.
Example: ./bash-minifier.sh -f=test.sh
Force
-F or --force
Should not be supplied with a parameter.
Disabled by default
If this option is enabled the script will skip any security checks and will therefore not prompt the user at any time.
Example: ./bash-minifier.sh -F -f=test.sh
Output
-o or --output
Requires a parameter
Defaults to STDOUT
This option specifies where to send the output.
STDOUT will simply send the output to stdout.
File will write the output to a file. To activate this option, simply specify a file path. If a file already exists in the filepath, the script will prompt the user and ask if the file should be overwritten.
Examples: ./bash-minifier.sh -F -f=test.sh -o=STDOUT./bash-minifier.sh -F -f=test.sh -o="$HOME/Desktop/output.sh"
Permission
-p or --permission
Requires a parameter
Defaults to u+x
This option will, in case of the output being a file, set the file permission to the content of the parameter
Example: ./bash-minifier.sh -F -f=test.sh -o=$HOME/Desktop/output.sh -p=u-r
Version
-V or --version
Outputs script version
Example: ./bash-minifier.sh -V
Exit codes
0: Everything went well
1: Unknown error
2: User declined to continue when warned
3: File does not exist
4: Unknown argument supplied to script
5: This script will not minify itself
6: Unknown output mode encountered