I'm reading the LinuxShellScriptingCookbookThirdEdition and practicing the code example from the book. The book gave the following command to replace rm with a back-up version.
alias rm='cp $@ ~/backup && rm $@'
however, when i put this line into my .bashrc and source it, the output after i ran rm was:
$ rm mail.txt
cp: missing destination file operand after '/home/qiaozhuoyue/backup'
Try 'cp --help' for more information.
which seems like $@ was not expand as expected, then I used echo "cp $@ ~/backup && rm $@" instead, from the output I found that the position of the first $@ was blank, that is, the former didn't expand as expected.
$ rm mail.txt
cp ~/backup && rm mail.txt
what I expect output is:
$ rm mail.txt
cp mail.txt ~/backup && rm mail.txt
Did I miss something?