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.
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.
This option chooses what file to read from.
Example: ./bash-minifier.sh -f=test.sh
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
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"
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
By default the output is checked with bash -n. If the input is valid bash but the output is not, nothing is written (exit code 8). This option skips that check.
Example: ./bash-minifier.sh --no-verify -f=test.sh
Outputs script version
Example: ./bash-minifier.sh -V
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
7: The input ends inside an unclosed construct
8: The output failed the bash -n check although the input passed it (a minifier bug, see --no-verify)
9: The output could not be written, or its permissions could not be set