A problem with Bash script

Posted by c.sokun on Ask Ubuntu See other posts from Ask Ubuntu or by c.sokun
Published on 2010-11-01T10:37:52Z Indexed on 2011/02/03 7:33 UTC
Read the original article Hit count: 400

Filed under:
|

I want to write a simple script to detect a file created by Windows virus, usually it create an .exe file with the same name as the directory it drop.

Here is the script it only work if the path name doesn't contain \n. Can someone help me fix this script please!

#!/bin/bash
if [ $# == 0 ]; then
    echo ""
    echo "==== Give me a directory to begin with! ===="
    echo ""
    exit
fi

for f in `find $1 -name '*.exe'` | do
    filename=`basename "$f" .exe`
    dir_name=`dirname "$f"`
    current_dir_name=`basename "$dir_name"`

    if [ $filename == $current_dir_name ]; then
        rm -f "$f"  # It can't remove file where path contain space or \n ??!!
    fi
done

© Ask Ubuntu or respective owner

Related posts about bash

Related posts about find