4

My bash version

$ bash --version
GNU bash, version 4.4.23(1)-release (x86_64-pc-msys)

My java version

$ java --version
openjdk 13.0.1 2019-10-15
OpenJDK Runtime Environment (build 13.0.1+9)
OpenJDK 64-Bit Server VM (build 13.0.1+9, mixed mode, sharing)

My kotlinc version

$ kotlinc -version
OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
info: kotlinc-jvm 1.3.50 (JRE 13.0.1+9)

What I tried

$ echo *
chap_six.kt clean.sh hello.jar hello.kt README.md start.sh
$ echo \*
*

My simple print program

// hello.kt
fun main(args: Array<String>) {
    println(args[0])
}

After compiling my simple print program

kotlinc hello.kt -include-runtime -d hello.jar

I expect to see the * symbol printed in the console when running the java .jar

Here's what I get

$ java -jar hello.jar *
chap_six.kt
$ java -jar hello.jar \*
.git
$ java -jar hello.jar "*"
.git
$ java -jar hello.jar "\*"
\$Recycle.Bin

I tried to apply what is suggested in this answer but it failed too

My hello.sh

#!/bin/bash
FOO="*"
set +f
GLOBIGNORE=*
java -jar hello.jar $FOO

and the attempt

$ ./hello.sh
.git

My hello2.sh also fails

#!/bin/bash
FOO="*"
set -f
java -jar hello.jar $FOO

And the attempt

$ ./hello2.sh 
.git

My shopt looks like this

$ shopt
autocd          off
cdable_vars     off
cdspell         off
checkhash       off
checkjobs       off
checkwinsize    off
cmdhist         on
compat31        off
compat32        off
compat40        off
compat41        off
compat42        off
compat43        off
completion_strip_exe    off
complete_fullquote      on
direxpand       off
dirspell        off
dotglob         off
execfail        off
expand_aliases  on
extdebug        off
extglob         off
extquote        on
failglob        off
force_fignore   on
globasciiranges off
globstar        off
gnu_errfmt      off
histappend      off
histreedit      off
histverify      off
hostcomplete    on
huponexit       off
inherit_errexit off
interactive_comments    on
lastpipe        off
lithist         off
login_shell     off
mailwarn        off
no_empty_cmd_completion off
nocaseglob      off
nocasematch     off
nullglob        off
progcomp        on
promptvars      on
restricted_shell        off
shift_verbose   off
sourcepath      on
xpg_echo        off

My set -o looks like this

$ set -o
allexport       off
braceexpand     on 
emacs           on
errexit         off
errtrace        off
functrace       off
hashall         on
histexpand      on
history         on
igncr           off
ignoreeof       off
interactive-comments    on
keyword         off
monitor         on
noclobber       off
noexec          off
noglob          off
nolog           off
notify          off
nounset         off
onecmd          off
physical        off
pipefail        off
posix           off
privileged      off
verbose         off
vi              off
xtrace          off
Julien Reszka
  • 888
  • 12
  • 25
  • have you also tried `"*"` and `"\*"`? – Lino Jan 09 '20 at 09:51
  • @LinosaysReinstateMonica yes I updated my question with the new failed attempts – Julien Reszka Jan 09 '20 at 09:59
  • Please also have a look at the linked [duplicate](https://stackoverflow.com/questions/102049/how-do-i-escape-the-wildcard-asterisk-character-in-bash), especially [this answer](https://stackoverflow.com/a/13484149/5515060) may help you – Lino Jan 09 '20 at 10:02
  • 1
    @LinosaysReinstateMonica I tried both set -f and set +f GLOBIGNORE it doesn't work with the java program, I updated my question with the failed attemps – Julien Reszka Jan 09 '20 at 10:10
  • can you give the output of `shopt` and that of `set -o`? – Léa Gris Jan 09 '20 at 10:52
  • Sorry, for those of us who are thick, could you make it clearer what your *desired* result actually is? – Gem Taylor Jan 09 '20 at 11:21
  • @LéaGris I updated my answer with the output of shopt and set -o – Julien Reszka Jan 09 '20 at 12:16
  • @GemTaylor I expect to see the * symbol printed in the console when running the java .jar with the * symbol as param. I want to know what is the input required for it to understand that I want to put the star symbol in the program – Julien Reszka Jan 09 '20 at 12:16
  • Try `java -jar hello.jar '\*'` (that is, with single quotes) – pepoluan Nov 21 '22 at 12:07

1 Answers1

0

Not a solution but a mean to frame the source of the issue.

Lets create hello.sh in Bash to compare how it handles the arguments array.

#!/usr/bin/env bash
# hello.sh
echo "$1"

Now create a test.sh to compare the output of same hello in Kotlin and Bash:

#!/usr/bin/env bash

for arg in '*' '\*' "'*'" '"*"'; do
  kotlinout="$(java -jar hello.jar $arg)"
  bashout="$(bash hello.sh $arg)"
  if [ "$kotlinout" = "$bashout" ]; then
    comp='are same';
  else
    comp='DIFFERS !!'
  fi
  printf 'Argument: %s\tKotink and Bash outputs %s\n' "$arg" "$comp";
  printf 'Kotlin output: %s\n' "$kotlinout";
  printf 'Bash output: %s\n' "$bashout";
done

Here is what it does in my environment:

$ bash test.sh 
Argument: * Kotink and Bash outputs are same
Kotlin output: chap_six.kt
Bash output: chap_six.kt
Argument: \*    Kotink and Bash outputs are same
Kotlin output: \*
Bash output: \*
Argument: '*'   Kotink and Bash outputs are same
Kotlin output: '*'
Bash output: '*'
Argument: "*"   Kotink and Bash outputs are same
Kotlin output: "*"
Bash output: "*"
Léa Gris
  • 17,497
  • 4
  • 32
  • 41