Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

fnmatch syntax error (C lang)

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
bentHnau
Posts: 148
Joined: 2014-01-07 01:43
Been thanked: 1 time

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: 1702
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
Been thanked: 1 time

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: 1403
Joined: 2009-09-10 20:15
Location: Saint-Petersburg, Russian Federation
Been thanked: 11 times

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: 1702
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