Korn Shell Script

  1. The problem statement, all variables and given/known data:

Write a korn shell script with an alfanumeric string as argument. The script lists the file's names in the current directory that contain the given string as substring and that can be read and written.

  1. Relevant commands, code, scripts, algorithms:

I can read the string from standard input and also print on screen the file's names which contain the string, but only if use the name of the file as parameter. I can't search the string among all the regular files in my directory and i have no idea on how to filter files basing on permissions.

  1. The attempts at a solution (include all code and scripts):
#!/bin/ksh
echo "Write a string"
read 
echo "Files which contain the string are:"
find . -type f | grep -l $REPLY stringhe.rtf

stringhe.rtf is a text file with some random strings created by me.
4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Universit� degli Studi di Trieste, Trieste, Italy, Vidimari, IN108

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Try this:

#!/bin/ksh

echo "Write a string"
read mystring

for file in `ls *$mystring*`
do
  if [[ -r $file && -w $file ]]
  then
    echo "$file is both readable and writeable"
  fi
done

This case the ls commands needs to be replaced by

find . -type f -name "*" -exec grep -l "$mystring" {} \; 

I tried your solution: i have a text file on my desktop which contain the word "cavallo". When i run the script from Desktop directory and i insert, when asked, the string "cavallo" this is the result:

Last login: Fri Jan  8 10:02:32 on ttys000
localhost:~ Teo$ cd Desktop
localhost:Desktop Teo$ ksh prova.ksh
Write a string
cavallo
ls: *cavallo*: No such file or directory
localhost:Desktop Teo$ 

I also tried that but it doesn't work, how can you filter files on their permissions with that?

Thank you.

---------- Post updated at 04:39 PM ---------- Previous update was at 10:14 AM ----------

Ok there was a misunderstading. The script seems to work, but not with every file, if there is a space in the name it doesn't work!