This is my first time bash scripting so I'm probably making an easy mistake.
Basically, I'm trying to write a script that gets the groups of a user, and if they are in a certain group, it will log that accordingly. Evidently there will be more functionality, but there's no point building that when I can't even get the regex working!
So far, I have this:
#!/bin/bash regex="^([a-zA-Z0-9\-_]+ : [a-zA-Z0-9\-_]+) (usergroup)$" # example output groups="username : username usergroup" echo "$groups" >> /home/jrdn/log if [[ "$groups" =~ $regex ]]; then echo "Match!" >> /home/jrdn/log else echo "No match" >> /home/jrdn/log fi
Every place I've tried that regex, it works. But in the bash script, it only ever outputs the
$groups, followed by
No match. So can someone tell me what's wrong with it?