A difficult script (for me)

Hi,
I'm a beginners, this is one of my first script, it's easy, but I don't know how to write this script:

The script receive in input 4 parameters:
1) user_name
2) r and/or w and/or x ( rwx, rw, x, ....)
3) u and/or g and/or o ( u, uo, ugo, ...)
4) the path name

The script print a list of normal files ( �-� with ls) created by user_name, with at least the permission specified as 2nd parameters for the groups specified as 3rd parameter , starting from the path name passed as 4th parameter.

Example of permission:
giving: rw, u
I look for � rw-......� using ls -lr (. is a generic character)
giving: rw, ugo
I look for � rw-rw-rw- �

I tryed in many ways, but for example i f I execute a simple script like this:
permission=-rw-r--r--
ls -lR | grep '^-$permission'

The script don't print anything on the screen, but I type in the shell:
ls -lR | grep '^-rw-r--r--'
the output is correct.

Moreover I don't know how to separate the colums of ls -lR using CUT (I suppose) to select oly the rows that are created by the user

So I understood I need help. Please help me.
PS: i have to write many script, and this is the simplest, so if I don't know how to write this, I'll never be able to write the others..

First, you won't get variable substitution inside single-quotes:

# x=123
# echo 'x=$x'       # string is literal
x=$x

# echo "x=$x"       # string is evaluated by the shell
x=123

# echo "x='$x'"
x='123'

Single-quotes lose their special quoting superpowers when inside double-quotes.

Also, if you pass a string to a command that includes a dash ("-") you run the risk of the string being interpreted as flags. You should therefore use the double-dash to indicate that no more flags are coming:

grep -c -v -- "$string" $file

So if "$string" includes any dashes, they will be ignored since they are after the "--".

Thanks.

Now, I don't know how to separate the colums of ls -lR using CUT (or using another command) to select oly the rows that are created by the user