fnmatch syntax error (C lang)

Programming languages, Coding, executables, and scripting.
Post Reply
Message
Author
bentHnau
Posts: 148
Joined: 2014-01-07 01:43

fnmatch syntax error (C lang)

#1 Post by bentHnau »

I can't figure out what's wrong with my call to fnmatch. The error is

Code: Select all

./fnm: line 5: syntax error near unexpected token `"fran*",'
./fnm: line 5: `	if (fnmatch("fran*", $file))'

Code: Select all

#!/bin/bash

for file in *
        do
        if (fnmatch("fran*", $file))
        then
        echo $file
        fi
done
exit 0

User avatar
phenest
Posts: 1704
Joined: 2010-03-09 09:38
Location: The Matrix

Re: fnmatch syntax error (C lang)

#2 Post by phenest »

You should pass filename and pattern. You have them the wrong way round:

Code: Select all

if (fnmatch($file, "fran*"))
ASRock H77 Pro4-M i7 3770K - 32GB RAM - Pioneer BDR-209D

bentHnau
Posts: 148
Joined: 2014-01-07 01:43

Re: fnmatch syntax error (C lang)

#3 Post by bentHnau »

Now I'm getting a similar error:

Code: Select all

./fnm: line 5: syntax error near unexpected token `$file,'
./fnm: line 5: `	if (fnmatch($file, "fran*"))'

peter_irich
Posts: 1328
Joined: 2009-09-10 20:15
Location: Saint-Petersburg, Russian Federation

Re: fnmatch syntax error (C lang)

#4 Post by peter_irich »

As I understand fnmatch() must be called from awk command or block, see "man 3am fnmatch".
And if-operator in bash seems otherise.

Peter.

User avatar
phenest
Posts: 1704
Joined: 2010-03-09 09:38
Location: The Matrix

Re: fnmatch syntax error (C lang)

#5 Post by phenest »

As peter_irich has pointed out, it doesn't look like this can be called from Bash. It can be done from python if that helps.
ASRock H77 Pro4-M i7 3770K - 32GB RAM - Pioneer BDR-209D

Post Reply