Not sure if this belongs in Java or Scripting...
Anyhow, I am trying to write a script to compile and run simple java programs. Creating a batch file in DOS is a piece of cake:
javac %1.java
java %1
However, in BASH it's a bit more complicated (at least I think it is). Here is what I have so far, I feel like it's close. My issue (I think) is that there is not a -o switch with javac to specify the output file name. is there another way?
#!/bin/bash
# Script to compile and execute a jave program
# Get file name without the .java extension
file_name=$(echo $1|sed 's/\(.*\)\.java/\1/')
# Compile the program with -o option to specify the name of the binary
javac -o $file_name.out $1
# If there were no compilation errors, run the program
if [[ $? -eq 0 ]]; then
./$file_name.out
fi