Computing.Net > Forums > Unix > csh - if: Missing file name

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

csh - if: Missing file name

Reply to Message Icon

Name: Leto
Date: November 13, 2002 at 17:28:47 Pacific
OS: SunOS 5.8
CPU/Ram: don't know
Comment:

I hope this is the right place to post this sort of question. I've been working on a simple csh assignment but I've hit a snag which is really strange to me. It's meant to be a simple matching program that matches words according to different criteria when different options are provided.

It all works fine except if I try to do option '-w' or an unrecognised option (the 'default' in the switch statement) it gives me an error: "if: Missing file name". I don't understand why all the other options work fine but these don't. Any help or advice would be really appreciated. ^_^.


#!/bin/csh -f

set b = 0

if ($#argv == 0) then
echo "Missing pattern"
echo "Usage: match [-opt ...] pattern [...]"
exit 0
endif


#if there is an option store it in opts and shift argv

if ($argv[1] =~ -?) then
set opts = $argv[1]
shift argv
set b = 1
endif

set word = `echo $argv[1] | awk '{gsub("_","."); print $0}'`

#if there was no option then do a simple grep
if ($b == 0) then
grep $word

else
switch ($opts)
case -i:
grep -i $word; exit 0
case -v:
grep -v $word; exit 0
case -w:
grep -w $word; exit 0
case -p:
grep ^$word; exit 0
case -s:
grep $word\$; exit 0
default:
echo "Unknown option: $opts"
echo "Usage: match [-opt ...] pattern [...]"
breaksw

endif




Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: csh - if: Missing file name

csh if syntax chk multiple files www.computing.net/answers/unix/csh-if-syntax-chk-multiple-files-/8266.html

flexibility in file naming schemes?? www.computing.net/answers/unix/flexibility-in-file-naming-schemes/570.html

Compare file names then move www.computing.net/answers/unix/compare-file-names-then-move-/7257.html