2

Trying to get scala and sbt setup on my home computer windows 10 to practice.

Have installed:

  • Scala version 2.12.4
  • Sbt 1.1.4
  • java version "9.0.4"
  • Java(TM) SE Runtime Environment (build 9.0.4+11)
  • Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)

Running the below command in git bash(in admin)

sbt new scala/projectname.g8

Getting this error

/c/Program Files (x86)/sbt/bin/sbt-launch-lib.bash: line 126: conditional binary operator expected
/c/Program Files (x86)/sbt/bin/sbt-launch-lib.bash: line 126: syntax error near `=~'
/c/Program Files (x86)/sbt/bin/sbt-launch-lib.bash: line 126: `  elif [[ "${JAVA_OPTS}" =~ Use.*GC ]] || [[ "${JAVA_TOOL_OPTIONS}" =~ Use.*GC ]] || [[ "${SBT_OPTS}" =~ Use.*GC ]] ; then'
/c/Program Files (x86)/sbt/bin/sbt: line 157: run: command not found

I've tried to reinstall all dependencies, repair sbt install.
When I go to the directory the files are hidden.

Code from c/Program Files (x86)/sbt/bin/sbt-launch-lib.bash line 120 - 133:

get_gc_opts () {
  local older_than_9=$(( $java_version < 9 ))

  if [[ "$older_than_9" == "1" ]]; then
    # don't need to worry about gc
    echo ""
  elif [[ "${JAVA_OPTS}" =~ Use.*GC ]] || [[ "${JAVA_TOOL_OPTIONS}" =~ Use.*GC ]] || [[ "${SBT_OPTS}" =~ Use.*GC ]] ; then
    # GC arg has been passed in - don't change
    echo ""
  else
    # Java 9+ so revert to old
    echo "-XX:+UseParallelGC"
  fi
}

Greatly appreciate any help on this!

SOLVED: the =~ operator is not supported in bash versions >3.0. reinstalling git bash for windows solved this issue.

The commands also work fine for jdk 1.8 or above.

crowgers
  • 232
  • 3
  • 19
  • [This page here](https://www.scala-lang.org/download/) says: "First, make sure you have the Java 8 JDK installed.", this might one of the problems, but it doesn't explain bash's error messages. What bash version do you use, and how (if you are on windows)? – Andrey Tyukin Apr 17 '18 at 20:54
  • @AndreyTyukin ok I'll try that. I'm using it with the git client for windows which has bash built-in: https://gitforwindows.org/. Bash version 3.1. – crowgers Apr 17 '18 at 21:01
  • Also possibly relevant: https://stackoverflow.com/questions/15510083/syntax-error-operator-in-msysgit-bash/18369265 , https://stackoverflow.com/a/30590949/2707792 – Andrey Tyukin Apr 17 '18 at 21:03

2 Answers2

3

You might try this (in any order):

Andrey Tyukin
  • 43,673
  • 4
  • 57
  • 93
  • 1
    Reinstalling both fixed the issue. The git client looks a lot different now so I think it was most likely this. Will investigate and post resolution. – crowgers Apr 17 '18 at 21:14
0

There's no reason to use bash-only syntax here. The following will work on all POSIX-compliant shells:

#!/bin/sh

seen=0
for var in "$JAVA_OPTS" "$JAVA_TOOL_OPTIONS" "$SBT_OPTS"; do
  case $var in
    *Use*GC*) seen=1; break ;;
  esac
done

[ "$seen" = 0 ] && echo "-XX:+UseParallelGC"
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • Unfortunately, this is only one small excerpt of the bash code, the first line at which the bash-specific syntax broke. The launcher scripts distributed with SBT are around 500 lines full of tricky version-checking and pattern-matching code, I'm not sure whether the OP (or anyone else) has the energy to rewrite it to be fully POSIX-compliant. – Andrey Tyukin Apr 17 '18 at 23:02