shellshsdkman

How to run SDKMAN on shell script


I am trying to run sdkman on a shell script that I call run.sh. This is what the inside of the shell script looks like:

sdk use java 8.0.302-open

When I run the command in a terminal, it works. But when I run it in a shell script, I get this error:

run.sh: 1: sdk: not found

Anyone knows how to fix this?


Solution

  • I fixed it for me; Although this may not work for others.

    I placed #!/bin/bash at the top of the shell script, and then added this after it:

    source "$HOME/.sdkman/bin/sdkman-init.sh"
    

    Then my shell script was able to be ran using:

    ./run.sh
    

    sdkman was able to work this time.