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.

3
  • This page here 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)? Commented Apr 17, 2018 at 20:54
  • @AndreyTyukin ok I'll try that. I'm using it with the git client for windows which has bash built-in: gitforwindows.org. Bash version 3.1. Commented Apr 17, 2018 at 21:01
  • Also possibly relevant: stackoverflow.com/questions/15510083/… , stackoverflow.com/a/30590949/2707792 Commented Apr 17, 2018 at 21:03

2 Answers 2

3

You might try this (in any order):

Sign up to request clarification or add additional context in comments.

1 Comment

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.
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"

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.