Modify

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#18756 closed defect (fixed)

Fix shellcheck warnings of shellscripts

Reported by: simon04 Owned by: simon04
Priority: normal Milestone: 20.02
Component: Core Version:
Keywords: bash shell Cc: sebastic

Description

https://www.shellcheck.net/ – ShellCheck, a static analysis tool for shell scripts

$ shellcheck linux/tested/usr/bin/josm 

In linux/tested/usr/bin/josm line 7:
ALTERNATIVE_JDK="`readlink -n -f /etc/alternatives/java`"
                 ^-- SC2006: Use $(...) notation instead of legacy backticked `...`.

Did you mean: 
ALTERNATIVE_JDK="$(readlink -n -f /etc/alternatives/java)"


In linux/tested/usr/bin/josm line 10:
ARCH="`dpkg --print-architecture 2> /dev/null || true`"
      ^-- SC2006: Use $(...) notation instead of legacy backticked `...`.

Did you mean: 
ARCH="$(dpkg --print-architecture 2> /dev/null || true)"


In linux/tested/usr/bin/josm line 16:
|| dpkg --get-selections 'openjdk-*-jre:$ARCH' | grep install$ > /dev/null ; then
                         ^-------------------^ SC2016: Expressions don't expand in single quotes, use double quotes for that.


In linux/tested/usr/bin/josm line 33:
    . /etc/default/josm
      ^---------------^ SC1091: Not following: /etc/default/josm was not specified as input (see shellcheck -x).


In linux/tested/usr/bin/josm line 40:
        if [ "z$ALTERNATIVE_JDK" = "z`readlink -n -f $jcmd`" ] && [ -z "${JAVACMD}" ]; then
                                     ^--------------------^ SC2006: Use $(...) notation instead of legacy backticked `...`.
                                                     ^---^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
        if [ "z$ALTERNATIVE_JDK" = "z$(readlink -n -f "$jcmd")" ] && [ -z "${JAVACMD}" ]; then


In linux/tested/usr/bin/josm line 49:
        if [ -x "$jcmd" -a -z "${JAVACMD}" ]; then
                        ^-- SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.


In linux/tested/usr/bin/josm line 58:
    if [ "`expr match \"${JAVACMD}\" 'java-9'`" != "0" ] || [ "`expr match \"${JAVACMD}\" 'java-10'`" != "0" ]; then
          ^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
           ^--^ SC2003: expr is antiquated. Consider rewriting this using $((..)), ${} or [[ ]].
                                                               ^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
                                                                ^--^ SC2003: expr is antiquated. Consider rewriting this using $((..)), ${} or [[ ]].

Did you mean: 
    if [ "$(expr match \"${JAVACMD}\" 'java-9')" != "0" ] || [ "$(expr match \"${JAVACMD}\" 'java-10')" != "0" ]; then


In linux/tested/usr/bin/josm line 60:
    elif [ "`expr match \"${JAVACMD}\" 'java-1'`" != "0" ]; then
            ^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
             ^--^ SC2003: expr is antiquated. Consider rewriting this using $((..)), ${} or [[ ]].

Did you mean: 
    elif [ "$(expr match \"${JAVACMD}\" 'java-1')" != "0" ]; then


In linux/tested/usr/bin/josm line 65:
        $JAVACMD $JAVA_OPTS -jar /usr/share/josm/josm.jar "$@"
                 ^--------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
        $JAVACMD "$JAVA_OPTS" -jar /usr/share/josm/josm.jar "$@"

For more information:
  https://www.shellcheck.net/wiki/SC2166 -- Prefer [ p ] && [ q ] as [ p -a q...
  https://www.shellcheck.net/wiki/SC1091 -- Not following: /etc/default/josm ...
  https://www.shellcheck.net/wiki/SC2016 -- Expressions don't expand in singl...

Attachments (0)

Change History (11)

comment:1 by simon04, 4 years ago

Resolution: fixed
Status: assignedclosed

In 15916/josm:

fix #18756 - Fix shellcheck warnings of shellscripts

comment:2 by skyper, 4 years ago

Are the changes from #!/bin/sh to #!/bin/bash really needed ?

comment:3 by simon04, 4 years ago

In POSIX sh, [[ ]] is undefined – https://www.shellcheck.net/wiki/SC2039

Is the Bash requirement a major concern?

comment:4 by Don-vip, 4 years ago

Cc: sebastic added
Keywords: bash shell added

@sebastic: is it a problem for Debian if our shell scripts explicitly target bash?

comment:5 by anonymous, 4 years ago

As long as you #!/bin/bash for scripts with bashisms that's fine.

comment:6 by Klumbumbus, 4 years ago

Milestone: 20.0320.02

comment:7 by sebastic, 4 years ago

The josm laucher script is broken in 15927:

Using /usr/lib/jvm/java-11-openjdk-amd64/bin/java to execute josm.
Unrecognized option: --add-modules java.scripting,java.sql -Djosm.restart=true -Djava.net.useSystemProxies=true 
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Version 0, edited 4 years ago by sebastic (next)

in reply to:  7 comment:8 by skyper, 4 years ago

It worked/works for me on Debian 10 (Buster).

comment:9 by anonymous, 4 years ago

It was most definitely broken with josm (0.0.svn15927+dfsg-1) in Debian unstable.

Which package are you using on buster? The offending changes in 15927 are not in buster-backports yet.

comment:10 by skyper, 4 years ago

I use latest from JOSM and tested from Debian buster-backports.
Had no problem, with version 1.5.svn15927.
Might be Debian related.

comment:11 by simon04, 4 years ago

In 15944/josm:

fix #18756 - Launch scripts: fix $JAVA_OPTS (patch by sebastic)

Unrecognized option: --add-modules java.scripting,java.sql -Djosm.restart=true -Djava.net.useSystemProxies=true

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain simon04.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.