Script in UNIX (Bash) to determine if the user is the owner of a file

bashscriptunix

Something that would take any number of arguments, where each argument would be a path to a file or directory. If the user does own a particular path then it should check it to see if the path represents a normal file AND if that file is executable. If it is, then your script should execute/run the file.

Thanks for any help I've been trying different things for too long and I'm frustrated.

Best Answer

magic() {
    for p in "$@"; do
        [ -O "$p" -a -x "$p" ] && /bin/sh "$p"
    done
}

read 'man test' to see what the checks do.

Related Question