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.

link|improve this question
Homework question? Regardless, you should really show what you've tried so far. – Dennis Williamson Oct 7 '09 at 13:34
feedback

2 Answers

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

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

link|improve this answer
1  
Illegible showing off. – Tadeusz A. Kadłubowski Oct 7 '09 at 14:22
@tkadlubo: indeed. part to blame is display of <code> enclosed stuff here on superuser. – akira Oct 7 '09 at 14:28
feedback

To get current user id you do:

id -u

to get owner of file, you do:

stat -c "%u" file.name

to test if one value is the same as the other you do:

if [ "$first" -eq "$second" ]
then
    ....
fi
link|improve this answer
...and for looping on arguments consider shift... – dmckee Oct 7 '09 at 13:21
feedback

Your Answer

 
or
required, but never shown