bash_minifier
bash_minifier copied to clipboard
Whitespace in conditions not squashed correctly
Minifying the following code
if [[ $(ls) = '' ]]
then
echo 'Empty folder.'
fi
generates this (invalid) bash script:
if [[ $(ls)= '' ]];then echo 'Empty folder.';fi
Bash complains about the equal sign following the closing parenthese directly with no intermediate whitespace.
bash: conditional binary operator expected
bash: syntax error near `'''
This behaviour also breaks with numerical calculations. If I where to use some command that needs multiple options and I would calculate some parameter on the fly like this
command --numeric-option $(( (10 * 2) - 5)) --next-option
The output of the minifier will make the output wrong:
command --numeric-option $(((10 * 2)- 5))--next-option
The take away is that it isn't always legal to remove spaces after ).