OK, so all I really want to do is backup single files as a time in the current directory with '.bak' extension.
Here is my current function that does this (jsyk, using Rocky Linux):
function backup { sudo cp $PWD/$1 $PWD/$1.bak; }
Although, Rocky loads it fine (it's inside ~/.bash_aliases
which is loaded from ~/.bashrc
, it seems to keep giving me this error:
cp: cannot stat '.bak': No such file or directory
Am I missing something? Or am I crazy for not thinking of something even simpler?
sudo
requires-E
and-H
to preserve environment variables andcp
requires-a
and-f
to keep files metadata and forces overwrite existing .bakfunction test { sudo -EH echo $PWD/$1.bak; }
Which seems to give me the proper output:/home/greg/file.txt.bak
echo
to get an idea what the command looks like after expansion.