Let's me explain why second if condition are required:
Lets use following script output:
%PATTERN%
Output line1
Output line2
Output line3%PATTERN%
There is no new line on end of output. Also this is happen then we
have only one line with out new line symbol at end. Without second if,
we will receive no output.
Possibly solution for your case:
I suppose you could overwrite your command prompt passing environment
variables PS1,PS2,PS4
With following values all output are fine:
PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] '
PS2='> '
PS4='+ '
Also I suppose we could pass some default prompt from out code.
Thoughts?
Best regards,
Andrei Sobolev.