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
Programming languages, Coding, Executables, Package Creation, and Scripting.
bentHnau
Posts: 148 Joined: 2014-01-07 01:43
Been thanked: 1 time
#1
Post
by 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
phenest
Posts: 1702 Joined: 2010-03-09 09:38
Location: The Matrix
#2
Post
by phenest » 2017-02-09 20:48
You should pass filename and pattern. You have them the wrong way round:
ASRock H77 Pro4-M i7 3770K - 32GB RAM - Pioneer BDR-209D
bentHnau
Posts: 148 Joined: 2014-01-07 01:43
Been thanked: 1 time
#3
Post
by 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*"))'
peter_irich
Posts: 1405 Joined: 2009-09-10 20:15
Location: Saint-Petersburg, Russian Federation
Been thanked: 11 times
#4
Post
by 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.
phenest
Posts: 1702 Joined: 2010-03-09 09:38
Location: The Matrix
#5
Post
by 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.
ASRock H77 Pro4-M i7 3770K - 32GB RAM - Pioneer BDR-209D