Skip to content

[launcher] basename for solaris#6711

Merged
headius merged 1 commit intojruby:jruby-9.2from
ahorek:solaris
Aug 18, 2021
Merged

[launcher] basename for solaris#6711
headius merged 1 commit intojruby:jruby-9.2from
ahorek:solaris

Conversation

@ahorek
Copy link
Contributor

@ahorek ahorek commented Jun 8, 2021

basename -- "$sym"

it fails on launch because "--" isn't a valid java command (it works on linux)

basename "$sym"

returns "java" on both platforms

@kares kares added this to the JRuby 9.3.0.0 milestone Aug 9, 2021
@headius
Copy link
Member

headius commented Aug 12, 2021

I will have @mrnoname1000 look at this since he has helped with this script recently. The original introduction of basename -- appears to have been a long time ago in b1fec0d and I'm pretty sure I just got it off some SO post or blog entry somewhere.

@ahorek
Copy link
Contributor Author

ahorek commented Aug 12, 2021

I was just testing something and I got a weird error at startup. I didn't find any similar report, but probably there aren't many Solaris users of JRuby.
I'm definitely not an expert on Bash & Solaris, so maybe there's a better way.

https://unix.stackexchange.com/questions/253524/dirname-and-basename-vs-parameter-expansion

@mrnoname1000
Copy link
Contributor

Looks like POSIX doesn't allow options to basename, so this is another GNU-ism we need to work around. Fortunately, basename operates purely on text, so it's pretty easy to implement in pure shell:

basename() {
    local base="$1"
    if [ -n "$base" ]; then
        # remove trailing slashes
        base=${base%"${base##*[!/]}"}
        # remove leading directories
        base=${base##*/}
        # if $1 is all slashes, base=/
        base=${base:-/}
    fi
    printf "%s\n" "$base"
}

The printf can be replaced with an alternate return method to avoid a subshell, such as RET=$base.

Also basename has a little-used feature to remove a suffix, this function doesn't implement that.

@headius
Copy link
Member

headius commented Aug 16, 2021

@mrnoname1000 Perhaps I should merge this as-is and you can push another PR with the pure-POSIX basename change?

@headius headius merged commit d2d36db into jruby:jruby-9.2 Aug 18, 2021
@mrnoname1000
Copy link
Contributor

Actually I overlooked that stackexchange link, the implementation there looks better than mine and seems more efficient. I'll create a PR with that instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants