You are not logged in.
Pages: 1
I have a script that runs
if [ -f ~/bin/*~ ]; then
rm ~/bin/*~
fiIn theory it checks to see if backup files exist in the bin directory, and then deletes them if they do.
But it seems that this does not work correctly and I haven't the slightest clue why. Any help?
Offline
Use
set -xat the start to see what it does.
CLI Paste | How To Ask Questions
Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L
Offline
Maybe it doesn't work when there are several files ending with ~. "man test" says "-f FILE", not "FILES".
Edit: you can also remove the test and use "rm -f", though it might be risky.
Last edited by stqn (2012-03-13 10:07:09)
Offline
You can't check for the existence of multiple files using -f in test.
What you can do is either get a list of files and iterate through the list of files ending in ~ or use find.
eg:
for file in *~; do rm $file; doneProbably best to use echo rather than rm to test.
Edit: also to prevent future ones appearing this in vimrc will work:
set backupdir=/tmpOr you can just turn them off.
If you use something like nano there may be a similar setting, I can't remember.
Last edited by skanky (2012-03-13 10:37:51)
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline
I must be missing something...
rm -f ~/bin/*~
edit: if you really want to see if files exist matching a given pattern, it's not entirely straight forward:
shopt -s nullglob
files=("$HOME"/bin/*~)
if (( ${#files[*]} )); then
# do stuff with "${files[@]}"
else
# you has no files
fiLast edited by falconindy (2012-03-13 12:46:24)
Offline
I must be missing something...
Hmmm, no but I was seeing something that wasn't there (that is, a reason for the extra step). ![]()
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline
Thank you very much for your replies.. I will try some of what you guy's suggested later on. I did end up turning off backups though. I just like to have a clean bin folder ![]()
Offline
Pages: 1