Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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 -fset 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 argvif ($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 $wordelse
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 [...]"
breakswendif

![]() |
![]() |
![]() |

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