I am trying to write a bash script that simply compiles a java file then runs it
#!/bin/bash
read name
javac $name
$name | sed -r "s/.java//" | java
but instead of running the java file, it opens java.
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
blah blah blah
Try substituting this:
Or, even better: just enter the main class without “.java”:
The point is, you need to pass an argument to the “java” command. You can’t just use a pipe from stdout.