I created a script that starts/stops a program on a couple different servers.
The server I wrote the script on has Bash Version 3.2.51(1)-release, and there are
a couple of different servers where the version is 3.1... and possibly some after version 3.
The problem I'm running into is this line below:
if [[ ! $@ =~ start|stop|restart|status|help ]]
echo "Error(1): No option given for start|stop|restart|status"
Now this line works just fine on the server I wrote it on, but on another server I tested it on with
Bash Version 3.1.17 I get this error for that line:
./test_script: line 51: syntax error in conditional expression: unexpected token `|'
./test_script: line 51: syntax error near `|s'
./test_script: line 51: ` if [[ ! $@ =~ start|stop|restart|status|help ]]'
So if I change the code on the older Bash Version Server, and I surround the pattern in either single or double quotes, the script executes without a hitch. But if I add that to the one with the newer Bash Version it reads the pattern as a literal string instead of a pattern. I've also tried surrounding the pattern in backslashes "/". Which works on the newer Bash Version, but again, not on the older one...?
Does anyone know of anyway I can express this where it would be compatible on both versions and possible even newer versions of Bash?
Any thoughts would be much appreciated.
Thanks in Advance,