bash_minifier icon indicating copy to clipboard operation
bash_minifier copied to clipboard

Whitespace in conditions not squashed correctly

Open loilo opened this issue 8 years ago • 1 comments

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 `'''

loilo avatar Jun 16 '17 11:06 loilo

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 ).

jakub-olczyk avatar Mar 06 '19 13:03 jakub-olczyk