monkeyc scripts on MacOSX...

Hi Monkey Team,

Could you please consider adding an "exec " in front of the last line of the various MacOSX scripts as this will save both memory and time... And quotes around $* as this will make the scripts work even for arguments with embedded spaces and/or special characters.

#!/bin/bash

MB_HOME="$( cd "$( dirname "$0" )" && pwd )"
exec java -classpath "$MB_HOME"/monkeybrains.jar com.garmin.monkeybrains.Monkeybrains -a "$MB_HOME"/api.db -u "$MB_HOME"/devices.xml "$*"
  • Neither of these changes should be necessary.

    I don't understand why you'd need the exec at all, and quoting $* seems wrong. If you were to invoke the script as script -a -b -c, the java program would be invoked as java ... "-a -b -c"... The three arguments to the script have been collapsed into one.

    If you are passing a string with spaces to a script, it is your responsibility to enclose that string in quotes.
  • Exec gets rid of the shell running the command. Back in the day, with limited RAM, people used it to save RAM since it got rid of a shell that's just waiting on the return of its child before exiting. In these days of Gb RAM, there's really no need. My various running instances of bash are taking ~ 2 Mb each at the moment.
  • Travis, your right! I just checked ksh(1), and I mean "$@" of cause, not "$*".

    "$@" is special: given script -a -b -c "$@" does not expand to "-a -b -c" but to "-a" "-b" "-c"! Even more importantly for script -a "be cool" -c "$@" will expand to "-a" "be cool" "-c" - e.g. 3 arguments - and $@ (without the quotes) will expand to -a be cool -c - e.g 4 arguments.
  • I don't see an issue in replacing $* with "$@".
  • Yes, it seems that $@ is more appropriate...

    [vitek@seacat] 319 % cat t.sh
    #!/bin/bash

    echo ========== \$@ ==========
    for i in "$@"
    do
    echo $i
    done

    echo ========== \$* ==========

    for i in "$*"
    do
    echo $i
    done

    [vitek@seacat] 320 % t.sh -a "be cool" -c
    ========== $@ ==========
    -a
    be cool
    -c
    ========== $* ==========
    -a be cool -c