How to use SDKMAN! to install packages from within scripts
Asked Answered
S

2

17

Having SDKMAN! installed (http://sdkman.io/), I can install packages from the command line using for example:

sdk install java 8u144-zulu

However, when I try to do the same thing from within a script "my-installer.sh", I get error message: "sdk: command not found".

my-installer.sh:

#!/bin/bash
sdk install java 8u144-zulu

What am I doing wrong?

Solarize answered 17/9, 2017 at 9:23 Comment(1)
I suggest to add full path to sdk command.Nasty
C
30

you need to source in ~/.sdkman/bin/sdkman-init.sh, like in

#!/bin/bash
. /home/alexw/.sdkman/bin/sdkman-init.sh
sdk install java 8u144-zulu

'sdk' is a bash function declared in sdkman-init.sh, and your first line (#!...) starts a new(!) shell.

hope that helps! weHe

Cristen answered 29/9, 2017 at 10:59 Comment(0)
G
5

Here's how to source sdkman-init.sh more generically:

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

This is similar to the code that SDKMAN adds to your .zshrc file:

#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
export SDKMAN_DIR="/Users/powers/.sdkman"
[[ -s "/Users/powers/.sdkman/bin/sdkman-init.sh" ]] && source "/Users/powers/.sdkman/bin/sdkman-init.sh"

Type which sdk if you'd like to see the function that's being sourced:

sdk () {
    COMMAND="$1"
    QUALIFIER="$2"
    case "$COMMAND" in
        (l) COMMAND="list"  ;;
        (ls) COMMAND="list"  ;;
        (v) COMMAND="version"  ;;
        (u) COMMAND="use"  ;;
...
...
Gunwale answered 9/11, 2020 at 3:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.