0

Is it possible to convert code written in Java (just basics like aritmeticts, string operation, cycles/conditions - nothing complicated) and compile it into bash script ?

I don't have enough time to learn bash properly but I need to do some bash scripting quickly.

Can I just write it in Java and convert it into Bash ? I would be easier for me then learning bash from the scratch.

Or is there any other language which can be compiled into bash ?

jmt
  • 719
  • 1
  • 9
  • 28
  • 2
    Why would you want to butcher Java in this way? What has it ever done to you? – Joe C Sep 18 '17 at 21:30
  • 2
    Possible duplicate of [Are there any languages that compile to Bash?](https://stackoverflow.com/questions/10239235/are-there-any-languages-that-compile-to-bash) – David Z Sep 18 '17 at 21:32
  • This will not end well. You may want to look at "jjs" in the JDK which allows you to write scripts in javascript. – Thorbjørn Ravn Andersen Sep 18 '17 at 21:42
  • 1
    What's wrong with simply running your compiled Java program using `java -jar ...` on the command line? –  Sep 18 '17 at 21:53

1 Answers1

3

There's nothing currently to compile Java into bash.

Do you need to execute in bash? Could you just compile it and run in terminal using Java? Java allows you to execute shell commands, if that's all you need.

There are a few bash preprocessors, but they're relatively old and seem unmaintained. For example this or there are several mentioned here.

Regardless, learning to use a preprocessor will almost definitely take more effort than just learning bash, since you'll have to learn both at the same time.

Bash is a fundamental and ubiquitous language, and I would strongly encourage you to take the time to learn some basic scripting - it can make your life a lot easier.

Bricky
  • 2,572
  • 14
  • 30