I try to change the rm command into a command that give me backup of the file and remove the file after.
function move_to_trash () {
unset rm;
cp -v "$@" "/home/`whoami`/backup/" && rm "$@";
}
alias rm='move_to_trash'
Output:
'file1' -> '/home/dorchester/backup/file1'
'file1' -> '/home/dorchester/backup/file1'
'file1' -> '/home/dorchester/backup/file1'
'file1' -> '/home/dorchester/backup/file1'
'file1' -> '/home/dorchester/backup/file1'
'file1' -> '/home/dorchester/backup/file1'
'file1' -> '/home/dorchester/backup/file1'
'file1' -> '/home/dorchester/backup/file1'
The cp command keep running without starting rm "$@" command, which is something really strange. This seems to be a infinite loop, I would like to know how can this loop happen. Also, I'm aware of existence solution that turn cp command into move to trash command such rmtrash, though I prefer bash scripting method.
unset rm
unsets a variable namedrm
. It doesn't affect aliases. – muru Aug 19 '19 at 04:34