Search code examples
sedzsh

Bash String Comparison With Regex Not Working


I'm trying to do a simple string comparison in zsh where one the arguments is the result of a sed call.

Yet I keep getting "zsh: missing end of string"

[ (sed -En s/'(^.+)-SNAPSHOT'/'\1'/p ./app_version.txt) = "1.20.11" ]

The app_version.txt file contains a Maven version. sed is stripping out "SNAPSHOT". app_version.txt

1.20.11-SNAPSHOT


Solution

  • It's because the output of your sed needs to be double quoted. Try this:

    [ "$(sed -En s/'(^.+)-SNAPSHOT'/'\1'/p ./app_version.txt)" = "1.20.11" ]