fnmatch syntax error (C lang)

Need help with C, C++, perl, python, etc?

fnmatch syntax error (C lang)

Postby bentHnau » 2017-02-09 19:27

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
Debian Jessie x64, Dell XPS 17 laptop
Qubes OS
bentHnau
 
Posts: 94
Joined: 2014-01-07 01:43
Location: California

Re: fnmatch syntax error (C lang)

Postby phenest » 2017-02-09 20:48

You should pass filename and pattern. You have them the wrong way round:
Code: Select all
if (fnmatch($file, "fran*"))
NEC Spirit 550 P4 3.8GHz HT - 2GB RAM - nVidia 7600GT - Pioneer BDR-209DBK
ASUS Sabertooth P67 i7 3770K - 32GB RAM - 2x nVidia 660GTX SLI'd
User avatar
phenest
 
Posts: 1571
Joined: 2010-03-09 09:38
Location: The Matrix

Re: fnmatch syntax error (C lang)

Postby bentHnau » 2017-02-09 22:23

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*"))'
Debian Jessie x64, Dell XPS 17 laptop
Qubes OS
bentHnau
 
Posts: 94
Joined: 2014-01-07 01:43
Location: California

Re: fnmatch syntax error (C lang)

Postby peter_irich » 2017-02-10 20:04

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

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

Re: fnmatch syntax error (C lang)

Postby phenest » 2017-02-10 20:52

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.
NEC Spirit 550 P4 3.8GHz HT - 2GB RAM - nVidia 7600GT - Pioneer BDR-209DBK
ASUS Sabertooth P67 i7 3770K - 32GB RAM - 2x nVidia 660GTX SLI'd
User avatar
phenest
 
Posts: 1571
Joined: 2010-03-09 09:38
Location: The Matrix


Return to Programming

Who is online

Users browsing this forum: No registered users and 4 guests

fashionable