Finding the directories with same permission and then apply some default UNIX commands

HI there. My teacher asked us to write a code for this question

Write a Unix shell script named 'mode' that accepts two or more arguments, a file mode, a command and an optional list of parameters and performs the given command with the optional parameters on all files with that given mode.
For example, mode 644 ls -l should perform the command ls -l on all files in the current directory that have mode 644.

I came up with a code as below:

#!/bin/sh

mode=$1

shift 1 

ls -l |awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/) \
         *2^(8-i));if(k)printf("%0o ",k);print }'|grep "$mode"

how can I ask the code to apply the rest of arguments in the command line to the result of the script?

Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.