As Kusalananda noted in his edit, the << syntax you're referring to is called a here document.
As other comments have noted, the intent of your script is somewhat vague, but consider structuring your script something like this:
user=me
ip=myhost
dir=Test
if ssh "$user"@$ip /bin/bash << SCRIPT
[[ ! -d ~/"$dir" ]]
SCRIPT
then
echo "Error: $dir doesnt exist"
exit 1
fi
echo the script continues
That way:
$ ssh me@myhost rm -rf Test
$ ./test.sh
Error: Test doesnt exist
$ ssh me@myhost mkdir Test
$ ./test.sh
the script continues
For a here document as simple as this example, a "here string" would also suffice, provided that $dir doesn't contain any uncooperative characters:
if ssh "$user"@$ip /bin/bash <<< "[[ ! -d ~/$dir ]]"
then
...
.debfilesin the user's home directory) because you can see the error message? Note that nothing will be written to theerror.txtfile becauseechowrites to standard output by default and you're redirecting its standard error stream (the file will still be truncated (emptied)).