Your regex has a few issues. Firstly, Bash doesn't support Perl extensions like \S
. Secondly, harmlessly but revealingly, you don't need to escape the slash, because the slash character has no special significance in regular expressions. (There are some languages like Awk which use slashes as separators around regexes; then you do have to escape them. But Bash is not one of those languages.)
Anyway, especially if you are not very comfortable with regex, I would refactor to use a case
statement instead. The syntax will seem alien at first if you are not already familiar with it, but I think you will find that this is actually quite readable, maintainable, and versatile (as well as portable to basic sh
).
case $(git branch | sed -n 's/^\* \(.*\)/\1/p') in
master/* | release/* )
env='prod';;
* )
env='dev';;
esac
cp ./firebase_keys/"$env"/* ./firebase
echo "$env firebase keys used"
Notice also how the current working directory is already the default for any relative paths; there is basically never a need to use $(pwd)
- or, in Bash, the more economical built-in variable $PWD
- unless you specifically need to force absolute paths. (Perhaps see also Difference between ./
and ~/
)