I am trying to create and use variables inside heredoc like this,
sudo su - postgres <<EOF
sudo su - postgres <<"EOF"
The shell evaluates the unquoted here document and performs variable interpolation before passing it to
IP is not a defined variable in the parent shell, it gets expanded to an empty string.
With quotes, you prevent variable interpolation by the parent shell, and so the shell run by
sudo sees and expands the variable.