Use redirection, command substitution, and parameter expansion. Double quotes are needed to preserve whitespace and special characters. The trailing x saves the trailing whitespacenewlines which would be otherwise removed in the command substitution.
#!/bin/bash
echo "$var"x > file
unset var
var="$(< file)"
var=${var%x}