The build.sbt
text file contains versions like this:
name := "happy"
scalaVersion := "2.11.8"
sparkVersion := "2.2.0"
I wrote a Bash script to parse out the PROJECT_NAME
and SCALA_VERSION
from the build.sbt
file:
PROJECT_NAME=$(cat build.sbt | grep "name :=" | cut -f 3 -d " " | tr -d '"')
SCALA_VERSION=$(cat build.sbt | grep "scalaVersion :=" | cut -f 3 -d " " | tr -d '"')
How can I write this more elegantly / robustly? I'm ok with an awk
or sed
approach, but don't want to add an external dependency to the script.
Here's some more of the script to see how the variables are being used.
if [ "$SCALA_VERSION" = "" ]
then
echo "SCALA_VERSION variable cannot be empty"
exit 1
fi
SCALA_BINARY_VERSION=${SCALA_VERSION%.*}
if [ "$SCALA_BINARY_VERSION" = "" ]
then
echo "SCALA_BINARY_VERSION variable cannot be empty"
exit 1
fi
echo "Create a GitHub release"
JAR_PATH=target/scala-${SCALA_BINARY_VERSION}/${PROJECT_NAME}_${SCALA_BINARY_VERSION}-${SPARK_VERSION}_${PROJECT_VERSION}.jar
hub release create -a $JAR_PATH -m "Release v${PROJECT_VERSION}" v${PROJECT_VERSION}