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] alias
alias 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 found
It looks correct in ~/.bashrc
—
alias ll='ls -al'
—but in the alias list I get this crazy thing:
[/home/acheong87] alias
alias 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 correct—so I can't figure out what hidden step is averting my attention.