Modify

Opened 3 months ago

Closed 3 months ago

Last modified 3 months 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 Changed 3 months ago by simon04

Resolution: fixed
Status: assignedclosed

In 15916/josm:

fix #18756 - Fix shellcheck warnings of shellscripts

comment:2 Changed 3 months ago by skyper

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

comment:3 Changed 3 months ago by simon04

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

Is the Bash requirement a major concern?

comment:4 Changed 3 months ago by Don-vip

Cc: sebastic added
Keywords: bash shell added

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

comment:5 Changed 3 months ago by anonymous

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

comment:6 Changed 3 months ago by Klumbumbus

Milestone: 20.0320.02

comment:7 Changed 3 months ago by sebastic

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.

This is caused by quoting $JAVA_OPTS, fixed with:

        $JAVACMD $JAVA_OPTS -jar /usr/share/josm/josm.jar "$@"
Last edited 3 months ago by Don-vip (previous) (diff)

comment:8 in reply to:  7 Changed 3 months ago by skyper

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

comment:9 Changed 3 months ago by anonymous

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 Changed 3 months ago by skyper

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 Changed 3 months ago by simon04

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.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.