home search about rss feed twitter ko-fi

Command Line Scripts (Scala 3 Video)

Introduction

The command-line scripts (using scala-cli) that are shown in the video follow.

The command-line I/O script

// CmdLine.sc
import scala.io.StdIn.readLine

val age = 33
val weight = 200.00

print("What’s your name? ")

val name = readLine()
println(s"You said your name is $name")
println(s"Your age is $age, and your weight is $weight.")

Run that like this:

scala-cli CmdLine.sc

The last “HTTP GET” script

#!/usr/bin/env -S scala-cli shebang
//> using scala 3
//> using dep "com.softwaremill.sttp.client3::core::3.8.15"

import sttp.client3.*

val backend = HttpURLConnectionBackend()
val response = basicRequest
                  .get(uri"http://httpbin.org/get")
                  .send(backend)
println(response)

Update: All of my new videos are now on
LearnScala.dev