alibaba/java-dns-cache-manipulator

View on GitHub
tool/src/bin/dcm

Summary

Maintainability
Test Coverage

Quote this to prevent word splitting.
Open

    if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Quote this to prevent word splitting

Problematic code:

ls -l $(getfilename)

Correct code:

# getfilename outputs 1 file
ls -l "$(getfilename)"

# getfilename outputs multiple files, linefeed separated
getfilename | while IFS='' read -r line
do
  ls -l "$line"
done

Rationale:

When command expansions are unquoted, word splitting and globbing will occur. This often manifests itself by breaking when filenames contain spaces.

Trying to fix it by adding quotes or escapes to the data will not work. Instead, quote the command substitution itself.

If the command substitution outputs multiple pieces of data, use a loop instead.

Exceptions

In rare cases you actually want word splitting, such as in

gcc $(pkg-config --libs openssl) client.c

This is because pkg-config outputs -lssl -lcrypto, which you want to break up by spaces into -lssl and -lcrypto. An alternative is to put the variables to an array and expand it:

args=( $(pkg-config --libs openssl) )
gcc "${args[@]}" client.c

The power of using an array becomes evident when you want to combine, for example, the command result with user-provided arguments:

compile () {
    args=( $(pkg-config --libs openssl) "${@}" )
    gcc "${args[@]}" client.c
}
compile -DDEBUG
+ gcc -lssl -lcrypto -DDEBUG client.c

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Quote this to prevent word splitting.
Open

readonly BASE="$(cd $(dirname "$0")/..; pwd)"
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Quote this to prevent word splitting

Problematic code:

ls -l $(getfilename)

Correct code:

# getfilename outputs 1 file
ls -l "$(getfilename)"

# getfilename outputs multiple files, linefeed separated
getfilename | while IFS='' read -r line
do
  ls -l "$line"
done

Rationale:

When command expansions are unquoted, word splitting and globbing will occur. This often manifests itself by breaking when filenames contain spaces.

Trying to fix it by adding quotes or escapes to the data will not work. Instead, quote the command substitution itself.

If the command substitution outputs multiple pieces of data, use a loop instead.

Exceptions

In rare cases you actually want word splitting, such as in

gcc $(pkg-config --libs openssl) client.c

This is because pkg-config outputs -lssl -lcrypto, which you want to break up by spaces into -lssl and -lcrypto. An alternative is to put the variables to an array and expand it:

args=( $(pkg-config --libs openssl) )
gcc "${args[@]}" client.c

The power of using an array becomes evident when you want to combine, for example, the command result with user-provided arguments:

compile () {
    args=( $(pkg-config --libs openssl) "${@}" )
    gcc "${args[@]}" client.c
}
compile -DDEBUG
+ gcc -lssl -lcrypto -DDEBUG client.c

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Declare and assign separately to avoid masking return values.
Open

     export JAVA_HOME=`/usr/libexec/java_home`
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Declare and assign separately to avoid masking return values.

Problematic code:

export foo="$(mycmd)"

Correct code:

foo=$(mycmd)
export foo

Rationale:

In the original code, the return value of mycmd is ignored, and export will instead always return true. This may prevent conditionals, set -e and traps from working correctly.

When first marked for export and assigned separately, the return value of the assignment will be that of mycmd. This avoids the problem.

Exceptions:

If you intend to ignore the return value of an assignment, you can either ignore this warning or use

foo=$(mycmd) || true
export foo

Shellcheck does not warn about export foo=bar because bar is a literal and not a command substitution with an independent return value. It also does not warn about local -r foo=$(cmd), where declaration and assignment must be in the same command.

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
Open

    JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Use cd ... || exit in case cd fails.

Problematic code:

cd generated_files
rm -r *.c

func(){
  cd foo
  do_something
}

Correct code:

cd generated_files || exit
rm -r *.c

# For functions, you may want to use return:
func(){
  cd foo || return
  do_something
}

Rationale:

cd can fail for a variety of reasons: misspelled paths, missing directories, missing permissions, broken symlinks and more.

If/when it does, the script will keep going and do all its operations in the wrong directory. This can be messy, especially if the operations involve creating or deleting a lot of files.

To avoid this, make sure you handle the cases when cd fails. Ways to do this include

  • cd foo || exit as suggested to just abort immediately
  • if cd foo; then echo "Ok"; else echo "Fail"; fi for custom handling
  • <(cd foo && cmd) as an alternative to <(cd foo || exit; cmd) in <(..), $(..) or ( )

Exceptions:

ShellCheck does not give this warning when cd is on the left of a || or &&, or the condition of a if, while or until loop. Having a set -e command anywhere in the script will disable this message, even though it won't necessarily prevent the issue.

If you are accounting for cd failures in a way shellcheck doesn't realize, you can disable this message with a [[directive]].

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Declare and assign separately to avoid masking return values.
Open

  local wdir=$(pwd)
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Declare and assign separately to avoid masking return values.

Problematic code:

export foo="$(mycmd)"

Correct code:

foo=$(mycmd)
export foo

Rationale:

In the original code, the return value of mycmd is ignored, and export will instead always return true. This may prevent conditionals, set -e and traps from working correctly.

When first marked for export and assigned separately, the return value of the assignment will be that of mycmd. This avoids the problem.

Exceptions:

If you intend to ignore the return value of an assignment, you can either ignore this warning or use

foo=$(mycmd) || true
export foo

Shellcheck does not warn about export foo=bar because bar is a literal and not a command substitution with an independent return value. It also does not warn about local -r foo=$(cmd), where declaration and assignment must be in the same command.

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
Open

readonly BASE="$(cd $(dirname "$0")/..; pwd)"
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Use cd ... || exit in case cd fails.

Problematic code:

cd generated_files
rm -r *.c

func(){
  cd foo
  do_something
}

Correct code:

cd generated_files || exit
rm -r *.c

# For functions, you may want to use return:
func(){
  cd foo || return
  do_something
}

Rationale:

cd can fail for a variety of reasons: misspelled paths, missing directories, missing permissions, broken symlinks and more.

If/when it does, the script will keep going and do all its operations in the wrong directory. This can be messy, especially if the operations involve creating or deleting a lot of files.

To avoid this, make sure you handle the cases when cd fails. Ways to do this include

  • cd foo || exit as suggested to just abort immediately
  • if cd foo; then echo "Ok"; else echo "Fail"; fi for custom handling
  • <(cd foo && cmd) as an alternative to <(cd foo || exit; cmd) in <(..), $(..) or ( )

Exceptions:

ShellCheck does not give this warning when cd is on the left of a || or &&, or the condition of a if, while or until loop. Having a set -e command anywhere in the script will disable this message, even though it won't necessarily prevent the issue.

If you are accounting for cd failures in a way shellcheck doesn't realize, you can disable this message with a [[directive]].

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Double quote to prevent globbing and word splitting.
Open

readonly PROG=`basename $0`
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Double quote to prevent globbing and word splitting.

Problematic code:

echo $1
for i in $*; do :; done # this done and the next one also applies to expanding arrays.
for i in $@; do :; done

Correct code:

echo "$1"
for i in "$@"; do :; done # or, 'for i; do'

Rationale

The first code looks like "print the first argument". It's actually "Split the first argument by IFS (spaces, tabs and line feeds). Expand each of them as if it was a glob. Join all the resulting strings and filenames with spaces. Print the result."

The second one looks like "iterate through all arguments". It's actually "join all the arguments by the first character of IFS (space), split them by IFS and expand each of them as globs, and iterate on the resulting list". The third one skips the joining part.

Quoting variables prevents word splitting and glob expansion, and prevents the script from breaking when input contains spaces, line feeds, glob characters and such.

Strictly speaking, only expansions themselves need to be quoted, but for stylistic reasons, entire arguments with multiple variable and literal parts are often quoted as one:

$HOME/$dir/dist/bin/$file        # Unquoted (bad)
"$HOME"/"$dir"/dist/bin/"$file"  # Minimal quoting (good)
"$HOME/$dir/dist/bin/$file"      # Canonical quoting (good)

When quoting composite arguments, make sure to exclude globs and brace expansions, which lose their special meaning in double quotes: "$HOME/$dir/src/*.c" will not expand, but "$HOME/$dir/src"/*.c will.

Note that $( ) starts a new context, and variables in it have to be quoted independently:

echo "This $variable is quoted $(but this $variable is not)"
echo "This $variable is quoted $(and now this "$variable" is too)"

Exceptions

Sometimes you want to split on spaces, like when building a command line:

options="-j 5 -B"
make $options file

Just quoting this doesn't work. Instead, you should have used an array (bash, ksh, zsh):

options=(-j 5 -B) # ksh: set -A options -- -j 5 -B
make "${options[@]}" file

or a function (POSIX):

make_with_flags() { make -j 5 -B "$@"; }
make_with_flags file

To split on spaces but not perform glob expansion, Posix has a set -f to disable globbing. You can disable word splitting by setting IFS=''.

Similarly, you might want an optional argument:

debug=""
[[ $1 == "--trace-commands" ]] && debug="-x"
bash $debug script

Quoting this doesn't work, since in the default case, "$debug" would expand to one empty argument while $debug would expand into zero arguments. In this case, you can use an array with zero or one elements as outlined above, or you can use an unquoted expansion with an alternate value:

debug=""
[[ $1 == "--trace-commands" ]] && debug="yes"
bash ${debug:+"-x"} script

This is better than an unquoted value because the alternative value can be properly quoted, e.g. wget ${output:+ -o "$output"}.


As always, this warning can be [[ignore]]d on a case-by-case basis.

this is especially relevant when BASH many not be available for the array work around. For example, use in eval or in command options where script has total control of the variables...

FLAGS="-av -e 'ssh -x' --delete --delete-excluded"
...
# shellcheck disable=SC2086
eval rsync $FLAGS ~/dir remote_host:dir

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Double quote to prevent globbing and word splitting.
Open

"$JAVACMD" -Xmx128m $DCM_OPTS -classpath $CLASSPATH com.alibaba.dcm.tool.DcmTool "$@"
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Double quote to prevent globbing and word splitting.

Problematic code:

echo $1
for i in $*; do :; done # this done and the next one also applies to expanding arrays.
for i in $@; do :; done

Correct code:

echo "$1"
for i in "$@"; do :; done # or, 'for i; do'

Rationale

The first code looks like "print the first argument". It's actually "Split the first argument by IFS (spaces, tabs and line feeds). Expand each of them as if it was a glob. Join all the resulting strings and filenames with spaces. Print the result."

The second one looks like "iterate through all arguments". It's actually "join all the arguments by the first character of IFS (space), split them by IFS and expand each of them as globs, and iterate on the resulting list". The third one skips the joining part.

Quoting variables prevents word splitting and glob expansion, and prevents the script from breaking when input contains spaces, line feeds, glob characters and such.

Strictly speaking, only expansions themselves need to be quoted, but for stylistic reasons, entire arguments with multiple variable and literal parts are often quoted as one:

$HOME/$dir/dist/bin/$file        # Unquoted (bad)
"$HOME"/"$dir"/dist/bin/"$file"  # Minimal quoting (good)
"$HOME/$dir/dist/bin/$file"      # Canonical quoting (good)

When quoting composite arguments, make sure to exclude globs and brace expansions, which lose their special meaning in double quotes: "$HOME/$dir/src/*.c" will not expand, but "$HOME/$dir/src"/*.c will.

Note that $( ) starts a new context, and variables in it have to be quoted independently:

echo "This $variable is quoted $(but this $variable is not)"
echo "This $variable is quoted $(and now this "$variable" is too)"

Exceptions

Sometimes you want to split on spaces, like when building a command line:

options="-j 5 -B"
make $options file

Just quoting this doesn't work. Instead, you should have used an array (bash, ksh, zsh):

options=(-j 5 -B) # ksh: set -A options -- -j 5 -B
make "${options[@]}" file

or a function (POSIX):

make_with_flags() { make -j 5 -B "$@"; }
make_with_flags file

To split on spaces but not perform glob expansion, Posix has a set -f to disable globbing. You can disable word splitting by setting IFS=''.

Similarly, you might want an optional argument:

debug=""
[[ $1 == "--trace-commands" ]] && debug="-x"
bash $debug script

Quoting this doesn't work, since in the default case, "$debug" would expand to one empty argument while $debug would expand into zero arguments. In this case, you can use an array with zero or one elements as outlined above, or you can use an unquoted expansion with an alternate value:

debug=""
[[ $1 == "--trace-commands" ]] && debug="yes"
bash ${debug:+"-x"} script

This is better than an unquoted value because the alternative value can be properly quoted, e.g. wget ${output:+ -o "$output"}.


As always, this warning can be [[ignore]]d on a case-by-case basis.

this is especially relevant when BASH many not be available for the array work around. For example, use in eval or in command options where script has total control of the variables...

FLAGS="-av -e 'ssh -x' --delete --delete-excluded"
...
# shellcheck disable=SC2086
eval rsync $FLAGS ~/dir remote_host:dir

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Declare and assign separately to avoid masking return values.
Open

  local basedir=$(pwd)
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Declare and assign separately to avoid masking return values.

Problematic code:

export foo="$(mycmd)"

Correct code:

foo=$(mycmd)
export foo

Rationale:

In the original code, the return value of mycmd is ignored, and export will instead always return true. This may prevent conditionals, set -e and traps from working correctly.

When first marked for export and assigned separately, the return value of the assignment will be that of mycmd. This avoids the problem.

Exceptions:

If you intend to ignore the return value of an assignment, you can either ignore this warning or use

foo=$(mycmd) || true
export foo

Shellcheck does not warn about export foo=bar because bar is a literal and not a command substitution with an independent return value. It also does not warn about local -r foo=$(cmd), where declaration and assignment must be in the same command.

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Double quote to prevent globbing and word splitting.
Open

"$JAVACMD" -Xmx128m $DCM_OPTS -classpath $CLASSPATH com.alibaba.dcm.tool.DcmTool "$@"
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Double quote to prevent globbing and word splitting.

Problematic code:

echo $1
for i in $*; do :; done # this done and the next one also applies to expanding arrays.
for i in $@; do :; done

Correct code:

echo "$1"
for i in "$@"; do :; done # or, 'for i; do'

Rationale

The first code looks like "print the first argument". It's actually "Split the first argument by IFS (spaces, tabs and line feeds). Expand each of them as if it was a glob. Join all the resulting strings and filenames with spaces. Print the result."

The second one looks like "iterate through all arguments". It's actually "join all the arguments by the first character of IFS (space), split them by IFS and expand each of them as globs, and iterate on the resulting list". The third one skips the joining part.

Quoting variables prevents word splitting and glob expansion, and prevents the script from breaking when input contains spaces, line feeds, glob characters and such.

Strictly speaking, only expansions themselves need to be quoted, but for stylistic reasons, entire arguments with multiple variable and literal parts are often quoted as one:

$HOME/$dir/dist/bin/$file        # Unquoted (bad)
"$HOME"/"$dir"/dist/bin/"$file"  # Minimal quoting (good)
"$HOME/$dir/dist/bin/$file"      # Canonical quoting (good)

When quoting composite arguments, make sure to exclude globs and brace expansions, which lose their special meaning in double quotes: "$HOME/$dir/src/*.c" will not expand, but "$HOME/$dir/src"/*.c will.

Note that $( ) starts a new context, and variables in it have to be quoted independently:

echo "This $variable is quoted $(but this $variable is not)"
echo "This $variable is quoted $(and now this "$variable" is too)"

Exceptions

Sometimes you want to split on spaces, like when building a command line:

options="-j 5 -B"
make $options file

Just quoting this doesn't work. Instead, you should have used an array (bash, ksh, zsh):

options=(-j 5 -B) # ksh: set -A options -- -j 5 -B
make "${options[@]}" file

or a function (POSIX):

make_with_flags() { make -j 5 -B "$@"; }
make_with_flags file

To split on spaces but not perform glob expansion, Posix has a set -f to disable globbing. You can disable word splitting by setting IFS=''.

Similarly, you might want an optional argument:

debug=""
[[ $1 == "--trace-commands" ]] && debug="-x"
bash $debug script

Quoting this doesn't work, since in the default case, "$debug" would expand to one empty argument while $debug would expand into zero arguments. In this case, you can use an array with zero or one elements as outlined above, or you can use an unquoted expansion with an alternate value:

debug=""
[[ $1 == "--trace-commands" ]] && debug="yes"
bash ${debug:+"-x"} script

This is better than an unquoted value because the alternative value can be properly quoted, e.g. wget ${output:+ -o "$output"}.


As always, this warning can be [[ignore]]d on a case-by-case basis.

this is especially relevant when BASH many not be available for the array work around. For example, use in eval or in command options where script has total control of the variables...

FLAGS="-av -e 'ssh -x' --delete --delete-excluded"
...
# shellcheck disable=SC2086
eval rsync $FLAGS ~/dir remote_host:dir

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
Open

    wdir=$(cd "$wdir/.."; pwd)
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Use cd ... || exit in case cd fails.

Problematic code:

cd generated_files
rm -r *.c

func(){
  cd foo
  do_something
}

Correct code:

cd generated_files || exit
rm -r *.c

# For functions, you may want to use return:
func(){
  cd foo || return
  do_something
}

Rationale:

cd can fail for a variety of reasons: misspelled paths, missing directories, missing permissions, broken symlinks and more.

If/when it does, the script will keep going and do all its operations in the wrong directory. This can be messy, especially if the operations involve creating or deleting a lot of files.

To avoid this, make sure you handle the cases when cd fails. Ways to do this include

  • cd foo || exit as suggested to just abort immediately
  • if cd foo; then echo "Ok"; else echo "Fail"; fi for custom handling
  • <(cd foo && cmd) as an alternative to <(cd foo || exit; cmd) in <(..), $(..) or ( )

Exceptions:

ShellCheck does not give this warning when cd is on the left of a || or &&, or the condition of a if, while or until loop. Having a set -e command anywhere in the script will disable this message, even though it won't necessarily prevent the issue.

If you are accounting for cd failures in a way shellcheck doesn't realize, you can disable this message with a [[directive]].

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Use $(..) instead of legacy ...
Open

    JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Use $(STATEMENT) instead of legacy `STATEMENT`

Problematic code

echo "Current time: `date`"

Correct code

echo "Current time: $(date)"

Rationale

Backtick command substitution `STATEMENT` is legacy syntax with several issues.

  1. It has a series of undefined behaviors related to quoting in POSIX.
  2. It imposes a custom escaping mode with surprising results.
  3. It's exceptionally hard to nest.

$(STATEMENT) command substitution has none of these problems, and is therefore strongly encouraged.

Exceptions

None.

See also

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Use $(..) instead of legacy ...
Open

    JAVACMD="`which java`"
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Use $(STATEMENT) instead of legacy `STATEMENT`

Problematic code

echo "Current time: `date`"

Correct code

echo "Current time: $(date)"

Rationale

Backtick command substitution `STATEMENT` is legacy syntax with several issues.

  1. It has a series of undefined behaviors related to quoting in POSIX.
  2. It imposes a custom escaping mode with surprising results.
  3. It's exceptionally hard to nest.

$(STATEMENT) command substitution has none of these problems, and is therefore strongly encouraged.

Exceptions

None.

See also

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Use $(..) instead of legacy ...
Open

    CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Use $(STATEMENT) instead of legacy `STATEMENT`

Problematic code

echo "Current time: `date`"

Correct code

echo "Current time: $(date)"

Rationale

Backtick command substitution `STATEMENT` is legacy syntax with several issues.

  1. It has a series of undefined behaviors related to quoting in POSIX.
  2. It imposes a custom escaping mode with surprising results.
  3. It's exceptionally hard to nest.

$(STATEMENT) command substitution has none of these problems, and is therefore strongly encouraged.

Exceptions

None.

See also

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Use $(..) instead of legacy ...
Open

case "`uname`" in
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Use $(STATEMENT) instead of legacy `STATEMENT`

Problematic code

echo "Current time: `date`"

Correct code

echo "Current time: $(date)"

Rationale

Backtick command substitution `STATEMENT` is legacy syntax with several issues.

  1. It has a series of undefined behaviors related to quoting in POSIX.
  2. It imposes a custom escaping mode with surprising results.
  3. It's exceptionally hard to nest.

$(STATEMENT) command substitution has none of these problems, and is therefore strongly encouraged.

Exceptions

None.

See also

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Use $(..) instead of legacy ...
Open

        javaExecutable="`readlink -f \"$javaExecutable\"`"
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Use $(STATEMENT) instead of legacy `STATEMENT`

Problematic code

echo "Current time: `date`"

Correct code

echo "Current time: $(date)"

Rationale

Backtick command substitution `STATEMENT` is legacy syntax with several issues.

  1. It has a series of undefined behaviors related to quoting in POSIX.
  2. It imposes a custom escaping mode with surprising results.
  3. It's exceptionally hard to nest.

$(STATEMENT) command substitution has none of these problems, and is therefore strongly encouraged.

Exceptions

None.

See also

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Use $(..) instead of legacy ...
Open

    readLink=`which readlink`
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Use $(STATEMENT) instead of legacy `STATEMENT`

Problematic code

echo "Current time: `date`"

Correct code

echo "Current time: $(date)"

Rationale

Backtick command substitution `STATEMENT` is legacy syntax with several issues.

  1. It has a series of undefined behaviors related to quoting in POSIX.
  2. It imposes a custom escaping mode with surprising results.
  3. It's exceptionally hard to nest.

$(STATEMENT) command substitution has none of these problems, and is therefore strongly encouraged.

Exceptions

None.

See also

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Use $(..) instead of legacy ...
Open

      javaHome="`dirname \"$javaExecutable\"`"
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Use $(STATEMENT) instead of legacy `STATEMENT`

Problematic code

echo "Current time: `date`"

Correct code

echo "Current time: $(date)"

Rationale

Backtick command substitution `STATEMENT` is legacy syntax with several issues.

  1. It has a series of undefined behaviors related to quoting in POSIX.
  2. It imposes a custom escaping mode with surprising results.
  3. It's exceptionally hard to nest.

$(STATEMENT) command substitution has none of these problems, and is therefore strongly encouraged.

Exceptions

None.

See also

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Use $(..) instead of legacy ...
Open

    JAVA_HOME=`java-config --jre-home`
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Use $(STATEMENT) instead of legacy `STATEMENT`

Problematic code

echo "Current time: `date`"

Correct code

echo "Current time: $(date)"

Rationale

Backtick command substitution `STATEMENT` is legacy syntax with several issues.

  1. It has a series of undefined behaviors related to quoting in POSIX.
  2. It imposes a custom escaping mode with surprising results.
  3. It's exceptionally hard to nest.

$(STATEMENT) command substitution has none of these problems, and is therefore strongly encouraged.

Exceptions

None.

See also

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Use $(..) instead of legacy ...
Open

    JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Use $(STATEMENT) instead of legacy `STATEMENT`

Problematic code

echo "Current time: `date`"

Correct code

echo "Current time: $(date)"

Rationale

Backtick command substitution `STATEMENT` is legacy syntax with several issues.

  1. It has a series of undefined behaviors related to quoting in POSIX.
  2. It imposes a custom escaping mode with surprising results.
  3. It's exceptionally hard to nest.

$(STATEMENT) command substitution has none of these problems, and is therefore strongly encouraged.

Exceptions

None.

See also

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Use $(..) instead of legacy ...
Open

    if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Use $(STATEMENT) instead of legacy `STATEMENT`

Problematic code

echo "Current time: `date`"

Correct code

echo "Current time: $(date)"

Rationale

Backtick command substitution `STATEMENT` is legacy syntax with several issues.

  1. It has a series of undefined behaviors related to quoting in POSIX.
  2. It imposes a custom escaping mode with surprising results.
  3. It's exceptionally hard to nest.

$(STATEMENT) command substitution has none of these problems, and is therefore strongly encouraged.

Exceptions

None.

See also

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Use $(..) instead of legacy ...
Open

readonly PROG=`basename $0`
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Use $(STATEMENT) instead of legacy `STATEMENT`

Problematic code

echo "Current time: `date`"

Correct code

echo "Current time: $(date)"

Rationale

Backtick command substitution `STATEMENT` is legacy syntax with several issues.

  1. It has a series of undefined behaviors related to quoting in POSIX.
  2. It imposes a custom escaping mode with surprising results.
  3. It's exceptionally hard to nest.

$(STATEMENT) command substitution has none of these problems, and is therefore strongly encouraged.

Exceptions

None.

See also

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Use $(..) instead of legacy ...
Open

    JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Use $(STATEMENT) instead of legacy `STATEMENT`

Problematic code

echo "Current time: `date`"

Correct code

echo "Current time: $(date)"

Rationale

Backtick command substitution `STATEMENT` is legacy syntax with several issues.

  1. It has a series of undefined behaviors related to quoting in POSIX.
  2. It imposes a custom escaping mode with surprising results.
  3. It's exceptionally hard to nest.

$(STATEMENT) command substitution has none of these problems, and is therefore strongly encouraged.

Exceptions

None.

See also

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Use $(..) instead of legacy ...
Open

  javaExecutable="`which javac`"
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Use $(STATEMENT) instead of legacy `STATEMENT`

Problematic code

echo "Current time: `date`"

Correct code

echo "Current time: $(date)"

Rationale

Backtick command substitution `STATEMENT` is legacy syntax with several issues.

  1. It has a series of undefined behaviors related to quoting in POSIX.
  2. It imposes a custom escaping mode with surprising results.
  3. It's exceptionally hard to nest.

$(STATEMENT) command substitution has none of these problems, and is therefore strongly encouraged.

Exceptions

None.

See also

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Use $(..) instead of legacy ...
Open

        javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Use $(STATEMENT) instead of legacy `STATEMENT`

Problematic code

echo "Current time: `date`"

Correct code

echo "Current time: $(date)"

Rationale

Backtick command substitution `STATEMENT` is legacy syntax with several issues.

  1. It has a series of undefined behaviors related to quoting in POSIX.
  2. It imposes a custom escaping mode with surprising results.
  3. It's exceptionally hard to nest.

$(STATEMENT) command substitution has none of these problems, and is therefore strongly encouraged.

Exceptions

None.

See also

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Use $(..) instead of legacy ...
Open

      javaHome=`expr "$javaHome" : '\(.*\)/bin'`
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Use $(STATEMENT) instead of legacy `STATEMENT`

Problematic code

echo "Current time: `date`"

Correct code

echo "Current time: $(date)"

Rationale

Backtick command substitution `STATEMENT` is legacy syntax with several issues.

  1. It has a series of undefined behaviors related to quoting in POSIX.
  2. It imposes a custom escaping mode with surprising results.
  3. It's exceptionally hard to nest.

$(STATEMENT) command substitution has none of these problems, and is therefore strongly encouraged.

Exceptions

None.

See also

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Use $(..) instead of legacy ...
Open

     export JAVA_HOME=`/usr/libexec/java_home`
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Use $(STATEMENT) instead of legacy `STATEMENT`

Problematic code

echo "Current time: `date`"

Correct code

echo "Current time: $(date)"

Rationale

Backtick command substitution `STATEMENT` is legacy syntax with several issues.

  1. It has a series of undefined behaviors related to quoting in POSIX.
  2. It imposes a custom escaping mode with surprising results.
  3. It's exceptionally hard to nest.

$(STATEMENT) command substitution has none of these problems, and is therefore strongly encouraged.

Exceptions

None.

See also

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Use $(..) instead of legacy ...
Open

    CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Use $(STATEMENT) instead of legacy `STATEMENT`

Problematic code

echo "Current time: `date`"

Correct code

echo "Current time: $(date)"

Rationale

Backtick command substitution `STATEMENT` is legacy syntax with several issues.

  1. It has a series of undefined behaviors related to quoting in POSIX.
  2. It imposes a custom escaping mode with surprising results.
  3. It's exceptionally hard to nest.

$(STATEMENT) command substitution has none of these problems, and is therefore strongly encouraged.

Exceptions

None.

See also

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Use $(..) instead of legacy ...
Open

        javaHome="`dirname \"$javaExecutable\"`"
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Use $(STATEMENT) instead of legacy `STATEMENT`

Problematic code

echo "Current time: `date`"

Correct code

echo "Current time: $(date)"

Rationale

Backtick command substitution `STATEMENT` is legacy syntax with several issues.

  1. It has a series of undefined behaviors related to quoting in POSIX.
  2. It imposes a custom escaping mode with surprising results.
  3. It's exceptionally hard to nest.

$(STATEMENT) command substitution has none of these problems, and is therefore strongly encouraged.

Exceptions

None.

See also

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Use $(..) instead of legacy ...
Open

  if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Use $(STATEMENT) instead of legacy `STATEMENT`

Problematic code

echo "Current time: `date`"

Correct code

echo "Current time: $(date)"

Rationale

Backtick command substitution `STATEMENT` is legacy syntax with several issues.

  1. It has a series of undefined behaviors related to quoting in POSIX.
  2. It imposes a custom escaping mode with surprising results.
  3. It's exceptionally hard to nest.

$(STATEMENT) command substitution has none of these problems, and is therefore strongly encouraged.

Exceptions

None.

See also

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Useless echo? Instead of 'echo $(cmd)', just use 'cmd'.
Open

    echo "$(tr -s '\n' ' ' < "$1")"
Severity: Minor
Found in tool/src/bin/dcm by shellcheck

Useless echo? Instead of echo $(cmd), just use cmd

Problematic code:

echo "$(cat 1.txt)"
echo `< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6`

Correct code:

cat 1.txt # In bash, but faster and still sticks exactly one newline: printf '%s\n' "$(<1.txt)"
# The original `echo` sticks a newline; we want it too.
< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6; echo

Rationale

The command substitution $(foo) yields the result of command foo with trailing newlines erased, and when it is passed to echo it generally just gives the same result as foo.

Exceptions

One may want to use command substitutions plus echo to make sure there is exactly one trailing newline. The special command substitution $(<file) in bash is also un-outline-able.

Anyway, echo is still not that reliable (see [[SC2039#echo-flags]]) and printf should be used instead.

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Expected an indentation at 4 instead of at 5.
Open

     #
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 8 instead of at 6.
Open

      JAVACMD="$JAVA_HOME/jre/sh/java"
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 8 instead of at 6.
Open

      JAVACMD="$JAVA_HOME/bin/java"
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  elif [ -f "$JAVA_HOME/../lib/tools.jar" ]; then
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 8 instead of at 6.
Open

      basedir=$wdir
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  echo "${basedir}"
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 5.
Open

     export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  [ -n "$CLASSPATH" ] &&
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  javaExecutable="`which javac`"
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 5.
Open

     exit 8
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 5.
Open

     export JAVA_HOME=`/usr/libexec/java_home`
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 5.
Open

     #
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  [ -n "$JAVA_HOME" ] &&
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  # TODO classpath?
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 8 instead of at 6.
Open

      javaHome=`expr "$javaHome" : '\(.*\)/bin'`
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  if [ -n "$JAVA_HOME"  ] ; then
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 8 instead of at 6.
Open

      # IBM's JDK on AIX uses strange locations for the executables
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  elif [ -f "$JAVA_HOME/../lib/tools.jar" ]; then
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 5.
Open

     echo "tools.jar/classes.jar NOT found!" 1>&2
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  fi
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  local basedir=$(pwd)
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  Darwin*) darwin=true
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 5.
Open

     #
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 5.
Open

     #
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  [ -n "$JAVA_HOME" ] &&
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  echo "Warning: JAVA_HOME environment variable is not set."
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 5.
Open

     # Apple JDKs
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 8 instead of at 6.
Open

      else
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  CYGWIN*) cygwin=true ;;
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 5.
Open

     #
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  [ -n "$JAVA_HOME" ] &&
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  else
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 5.
Open

     #
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 5.
Open

     export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 5.
Open

     # Oracle JDKs
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  while [ "$wdir" != '/' ] ; do
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 8 instead of at 6.
Open

      JAVA_HOME="$javaHome"
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  if [ -f "$1" ]; then
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  if [ -r /etc/gentoo-release ] ; then
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  fi
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  [ -n "$CLASSPATH" ] &&
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 5.
Open

     #
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 8 instead of at 6.
Open

      javaHome="`dirname \"$javaExecutable\"`"
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  exit 1
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  if [ -f "$JAVA_HOME/lib/tools.jar" ]; then
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  MINGW*) mingw=true;;
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 5.
Open

     # Apple JDKs
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  done
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 5.
Open

     # Apple JDKs
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  fi
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 8 instead of at 6.
Open

      fi
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  fi
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  echo "  We cannot execute $JAVACMD" >&2
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  else
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 5.
Open

     export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  local wdir=$(pwd)
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 8 instead of at 6.
Open

      break
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 5.
Open

     #
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  fi
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 8 instead of at 6.
Open

      if $darwin ; then
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 8 instead of at 6.
Open

      export JAVA_HOME
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  echo "Error: JAVA_HOME is not defined correctly." >&2
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

Expected an indentation at 4 instead of at 2.
Open

  elif [ -f "$JAVA_HOME/../Classes/classes.jar" ]; then
Severity: Minor
Found in tool/src/bin/dcm by editorconfig

There are no issues that match your filters.

Category
Status