There are two easy solutions. One is to use a here document instead of quote marks. Use the quoted form of the here document (where the
<<EOF part contains a quote character) to turn off variable and command substitution inside the here document.
cat <<\EOF >>~/.bashrc
alias myname='export PATH="/path/to/bin:$PATH"'
The other is to use single quotes around the string you want to print. You can effectively escape a single quote in a single-quoted literal by using
'\'' — end the single-quoted literal, append a literal single quote, and start a new single-quoted literal.
echo 'alias myname='\''export PATH="/path/to/bin:$PATH"'\'''
(You can optimize away the final empty string literal
On some shells,
echo command doesn't print its argument literally, which is why the robust way to print a string is with
printf '%s\n' 'alias myname='\''export PATH="/path/to/bin:$PATH"'\'''
In this specific case,
echo works too since the only expansions it performs concern backslashes and a leading