Search code examples
shellcsh

How to use wildcard to be the variable and give it to a csh script


I'm not very sure how to describe my question, so I just use an example to explain what I want to do.

Example:

There are three files in a directory

aaa.txt, bbb.txt, ccc.log

I would use grep to check whether some keyword is in txt files, just like the following command.

grep keyword *.txt

I want to use a csh script to do the same thing. So I write a csh script.

test.sh

#!/bin/csh -f
grep 'keyword' $1

then I call it the same way.

./test.sh *.txt

It seems it just perform the grep to the first file in its list. How could I let test.sh go through to every file?


Solution

  • Try:

    #!/bin/csh -f
    grep 'keyword' $argv