This is a really simple RegEx that isn’t working, and I can’t figure out why. According to this, it should work.
I’m on a Mac (OS X 10.8.2).
script.sh
#!/bin/bash
ZIP="software-1.3-licensetypeone.zip"
VERSION=$(sed 's/software-//g;s/-(licensetypeone|licensetypetwo).zip//g' <<< $ZIP)
echo $VERSION
terminal
$ sh script.sh
1.3-licensetypeone.zip
Looking at the regex documentation for OS X 10.7.4 (but should apply to OP’s 10.8.2), it is mentioned in the last paragraph that
sed, without any options, uses basic regular expression (BRE).To use
|in OS X or BSD’ssed, you need to enable extended regular expression (ERE) via-Eoption, i.e.p/s:
\|in BRE is a GNU extension.Alternative ways to extract version number
chop-chop (parameter expansion)
sedYou don’t necessarily have to match strings word-by-word with shell patterns or regex.