0

I have a Java program that prints something using System.out.println() . How can I get that output into my bash program? I am trying something like this:

$offset = java -jar /path/to/jar/myjar.jar $arg1 $arg2

But that line will just give me the following error:

0: command not found
  • 4
    `offset=$(java -jar /path/to/jar/myjar.jar $arg1 $arg2)` (notice also no `$` before `offset`) – Federico klez Culloca Jan 22 '20 at 15:38
  • 1
    Does this answer your question? [How do I set a variable to the output of a command in Bash?](https://stackoverflow.com/questions/4651437/how-do-i-set-a-variable-to-the-output-of-a-command-in-bash) – dibery Jan 22 '20 at 16:09
  • Apparently `offset` was already set to 0 and so `$offset` literally tries to run a command with that name, with `=` and `java` etc as parameters. Maybe see also https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable/27701642 – tripleee Jan 22 '20 at 19:04

0 Answers0