Use shellescape(url, 1) instead of escape(url, "#")