Artificial intelligent assistant

Heredocument indented inside a function fails on execution I have this a script containing a function and a function call. Inside the function there's an heredocument: #!/bin/bash DWA() { ...... mysql -u root -p <<-MYSQL ...... MYSQL } DWA ## The problem The execution breaks with an error regarding heredocument delimiter (likely, due to the delimiter `MYSQL` being indented). The problem didn't happen when I removed all leads (whitespaces/tabs). ## My question Given functions strip all leading tabs (I don't know about other types of leads, like whitespaces), why do I encounter this problem and what, if at all, can be done against that?

You're probably not indenting your heredoc with tabs. Every line of the heredoc must be indented with a tab, including the first line (where the delimiter is introduced). Here is a test case for you:


echo -e 'function heredoc() {\
\tcat <<-HEREDOC\
\t\tThis is a test\tHEREDOC\
} heredoc' > heredoc.sh


Try running that command and then running `heredoc.sh`. You should get the following output:


This is a test.


Alternatively, here is the same script but with the first line indented with spaces instead of a tab:


echo -e 'function heredoc() {\
cat <<-HEREDOC\
\t\tThis is a test\tHEREDOC\
} heredoc' > heredoc2.sh


If we run `heredoc2.sh` we get the following error output:


bash heredoc2.sh
heredoc2.sh: line 4: warning: here-document at line 2 delimited by end-of-file (wanted `HEREDOC')
heredoc2.sh: line 5: syntax error: unexpected end of file

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy b65dab5cccfdf5807d8751c9ffd05fbf