[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: diff files matching a pattern

Kamaraju S Kusumanchi wrote:

I must be doing something wrong here. Consider this reduced problem. I tried
to write a script to list all the files matching a specific pattern.

$cat ~/bin/patlist
#! /bin/sh
# to list all the files matching a given pattern
# call as patlist <pattern>
for file in $pattern; do
  echo $file

$ls file*
file1.txt  file2.txt  file3.txt

$patlist file*

That is for some reason patlist script lists only the first file the matches
the pattern and not all the files.

The pattern should be in quotes, so that the shell does not expand it and it gets passed to your script.

So it should be
$patlist "file*"

Raj Kiran Grandhi
At the source of every error which is blamed on the computer, you will find at least two human errors, including the error of blaming it on the computer.

Reply to: