Some versions of bash will not catch \s way we are used to in other languages ββ/ flavors. One version that it doesn't catch \s is on my MacBook Air with GNU bash, version 3.2.48(1)-release-(x86_64-apple-darwin12) .
And when creating the value of a variable, there should be no spaces around = .
As Ken-YN also has some problems in the comments on your post, I fixed it in my code below.
This should do it if the problem is \s :
#!/bin/bash re='^(-l\ )?(-s\ [0-9]+\ )?([a-zA-Z0-9]+)(\ [a-zA-Z0-9]+)?$' if [[ $@ =~ $re ]]; then echo 'cool' fi
No need to avoid spaces like me, but itβs easier for me to read this way.
source share