csh script to search for files and display result

Hello all. I'm a long time browser, first time poster...Be gentle :slight_smile:

I don't use csh much, but have been asked to make a small script for our HP-UX systems to search for a report file(s) or summary file and display the result (I was using vuepad, but this probably is just
complicating things)

My latest error is <if: expression> after if ($type =="R".... I can't see what's wrong.. Can anyone help..?

Here's the code.

#!/usr/bin/csh
set sumdir = ( /users/probe/buffer/summary/ )
set reportdir = ( /users/probe/buffer/reports/)
printf "\n enter lot number, lower case, \n E.G. p260091p1 \n"
set lot = $<
printf "\n Report or Summary \n (R or S) \n ? "
set type = $<
if ( $type == "R" ) then
type ="r"
set files = ( `ls $reportdir | grep $lot ` )
endif
if ( $type =="S" ) then
$type ="s"
set files = ( `ls $sumdir | grep $lot ` )
else
printf "\n Type only R or S \n "
endif

set z = 1
printf "\nWHich file do you want to view?\n\n"
while ($z <= $#files)
printf "\tFILE %2d = %s\n" $z $files[$z]
set z = $z + 1
end
set last = $z - 1
printf "\nSelect (0-$last):"
set choice = ($<)
if ( $choice < 0 || $choice > $last ) then
printf "No Such File.\n"
goto END
endif
if ( $choice > 0 ) then
set FILE = ( $files[$choice] )
else
set FILE = ( $files )
endif
foreach oneFILE ( $FILE )

if $file ="r" then

/usr/vue/bin/vuepad $reportdir$oneFILE
else
/usr/vue/bin/vuepad $sumdir$oneFILE
endif
end
END:
#EOF

Are you sure you get the error at the if ( $test == "R" ) ??

When I ran your script, I got the same error at the == "S" part. There you seem to need a space between == and "S".

Why couldn't I see that..? I am just careless after writing so much code in langages that just don't care about these things..

My next sticky point is

while ($z <= $#files)
printf "\tFILE %2d = %s\n" $z $files[$z]
set z = $z + 1
end

Is the syntax for <while> ok? When executed I get ... files: Undefined Variable.

I don't know anything about arrays in csh.

Do you still need help with this?