Your function is somewhat wrong. It should use $@
instead of $1
that is
function pb() {
echo "$@" | pbcopy
}
The result:
samveen@minime:/tmp $ function pb () { echo "$@" | pbcopy ; }
samveen@minime:/tmp $ pb !2030
pb file `which bzcat`
//result: `file /bin/bzcat` is in the clipboard
samveen@minime:/tmp $
To explain why the alias
doesn't work, the !!
is inside single quotes, and history replacement happens if !!
isn't quoted. As it is a replacement on the command history, which is interactive by definition, saving it into variables and aliases is very tricky.