Hey guys,
I'm fairly new to bash scripting, so bear with me
What I want to achieve is reading a file (.php), find the phrase 'WACHTWOORD' (password) in it, and collect the password and a part of the filename in a list.
The filename is always 'settings_{name}.php' and the part I'm looking for in the file is this 'define('WACHTWOORD','password');'
I'm using 2 regexpressions and the first one seems to work just fine, but the second one gives me an error:
list.sh: line 27: syntax error in conditional expression: unexpected token `('
list.sh: line 27: syntax error near `*,\'(.'
list.sh: line 27: ` if [[ $line =~ *,\'(.*)\'* ]] ; then'
Here is my code, I hope anyone can explain why the second one fails.
It's probably worth noting the server runs bash --version 3.1.17(1)-release (x86_64-pc-linux-gnu).
Note: I have tried surrounding the regexp with both ' and *, both give the same message
#!/bin/bash
FILES="../settings_*.php"
for f in $FILES
do
for line in `cat $f | grep "'WACHTWOORD'"`; do
# Filter out Praktijk
if [[ $f =~ '^../settings_(.*).php$' ]] ; then
praktijk="${BASH_REMATCH[1]}"
else
praktijk=$f
fi
# Filter out password
# the file contains: define('WACHTWOORD','password');
if [[ $line =~ *,\'(.*)\'* ]] ; then
password="${BASH_REMATCH[1]}"
else
password=$line
fi
echo $praktijk:$password
done
done