Be aware that on *nix, the -f file test will be true for a symbolic link that points to a plain file. Apply the -l test as well if this is a concern.
$ cat > rubbish a load of rubbish $ ln -s rubbish linkToRubbish $ cat rubbish a load of rubbish $ cat linkToRubbish a load of rubbish $ $ ls -l rubbish linkToRubbish lrwxrwxrwx 1 johngg None 7 May 21 10:51 linkToRubbish -> rubbish -rw-r--r-- 1 johngg None 18 May 21 10:51 rubbish $ $ perl -le ' > $file = q{linkToRubbish}; > unlink $file if -f $file;' $ ls -l rubbish linkToRubbish ls: cannot access linkToRubbish: No such file or directory -rw-r--r-- 1 johngg None 18 May 21 10:51 rubbish $ $ ln -s rubbish linkToRubbish $ cat linkToRubbish a load of rubbish $ $ perl -le ' > $file = q{linkToRubbish}; > unlink $file if -f $file and not -l $file;' $ ls -l rubbish linkToRubbish lrwxrwxrwx 1 johngg None 7 May 21 11:01 linkToRubbish -> rubbish -rw-r--r-- 1 johngg None 18 May 21 10:51 rubbish $
I hope this is of interest.
Cheers,
JohnGG
In reply to Re: code explanation
by johngg
in thread code explanation
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |