I'd like an alias that additionally appends itself to ~/.bashrc, e.g.function tailias{    $(echo alias $1='${*:2}' | tee -a ~/.bashrc)}I'm using tee to split the command to ~/.bashrc while leaving the stdout intact to be run by $().This works fine for aliasing one-word commands, e.g.[/home/acheong87] tailias f g[/home/acheong87] aliasalias f='g'and I see it appended to my ~/.bashrc. But for commands with spaces, I get[/home/acheong87] tailias ll 'ls -al'-bash: alias: -al: not foundIt looks correct in ~/.bashrcalias ll='ls -al'but in the alias list I get this crazy thing:[/home/acheong87] aliasalias ll=''\''ls'I've tried putting the quotes in different places, to no avail. I've reduced the function to just the echo, and like in the ~/.bashrc, it looks correctso I can't figure out what hidden step is averting my attention.
Command substitution interpreting spaces within quotes as argument separators
bash;quoting;alias;arguments;command substitution
You can eval to achieve what you want:function tailias{    eval $(echo alias $1='${*:2}' | tee -a ~/.bashrc)}This is better expained in this question (where an alternative solution is given)https://stackoverflow.com/questions/11079342/execute-command-containing-quotes-from-shell-variableor directly in the bash FAQ:http://mywiki.wooledge.org/BashFAQ/050