ElektraInitiative / libelektra

Elektra serves as a universal and secure framework to access configuration settings in a global, hierarchical key database.
https://www.libelektra.org
BSD 3-Clause "New" or "Revised" License
208 stars 123 forks source link

fix bashism #1256

Closed markus2330 closed 7 years ago

markus2330 commented 7 years ago

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=772254

add it to build job where scripts are installed?

markus2330 commented 7 years ago
checkbashisms scripts/*
possible bashism in scripts/benchmark_augeas_hosts.sh line 14 (time):
    { time -f "%e" $1 > /dev/null; } 2>&1
possible bashism in scripts/benchmark-createtree line 31 ($RANDOM):
                echo "$pad<key basename=\"$k-${RANDOM}${RANDOM}\" value=\"$k ${RANDOM}${RANDOM}\"></key>"
possible bashism in scripts/benchmark-createtree line 34 ($RANDOM):
                $KDB set "$myRoot/${RANDOM}${RANDOM}" \
                        "${RANDOM}${RANDOM}"
possible bashism in scripts/benchmark-createtree line 45 ($RANDOM):
                        genLevel `expr $level + 1` "${RANDOM}${RANDOM}"
possible bashism in scripts/benchmark-createtree line 56 ($RANDOM):
genLevel 1 ${RANDOM}
possible bashism in scripts/benchmark_libsplit.sh line 16 (time):
        WALLTIME=$( (time -p $BENCHMARK) 2>&1 )
possible bashism in scripts/build-homepage line 27 (ulimit):
ulimit -c unlimited
possible bashism in scripts/build-homepage line 72 (ulimit):
ulimit -a
script scripts/CMakeLists.txt does not appear to have a #! interpreter line;
you may get strange results
script scripts/configure-common does not appear to have a #! interpreter line;
you may get strange results
possible bashism in scripts/configure-debian line 8 (sourced script with arguments):
. "$(dirname "$0")/configure-common"
possible bashism in scripts/configure-debian-debug line 8 (sourced script with arguments):
. "$(dirname "$0")/configure-common"
possible bashism in scripts/configure-debian-log line 8 (sourced script with arguments):
. "$(dirname "$0")/configure-common"
possible bashism in scripts/configure-debian-musl line 3 (sourced script with arguments):
. "$(dirname "$0")/configure-common"
possible bashism in scripts/configure-debian-wheezy line 3 (sourced script with arguments):
. "$(dirname "$0")/configure-common"
possible bashism in scripts/configure-home line 6 (sourced script with arguments):
. "$(dirname "$0")/configure-common"
possible bashism in scripts/configure-ini line 3 (sourced script with arguments):
. "$(dirname "$0")/configure-common"
possible bashism in scripts/configure-mingw-w64 line 3 (sourced script with arguments):
. "$(dirname "$0")/configure-common"
possible bashism in scripts/configure-xdg line 3 (sourced script with arguments):
. "$(dirname "$0")/configure-common"
script scripts/filter-coverage.awk.in does not appear to have a #! interpreter line;
you may get strange results
script scripts/find-tools does not appear to be a /bin/sh script; skipping
could not find any possible bashisms in bash script scripts/generate-news-entry
script scripts/kdb-bash-completion does not appear to have a #! interpreter line;
you may get strange results
possible bashism in scripts/kdb-bash-completion line 16 (bash arrays, ${name[0|*|@]}):
        local cur="${COMP_WORDS[COMP_CWORD]}"
possible bashism in scripts/kdb-bash-completion line 17 (bash arrays, ${name[0|*|@]}):
        local prev="${COMP_WORDS[COMP_CWORD-1]}"
possible bashism in scripts/kdb-bash-completion line 23 (alternative test command ([[ foo ]] should be [ foo ])):
        if [[ $COMP_CWORD -eq 1 ]]
possible bashism in scripts/kdb-bash-completion line 25 ($'...' should be "$(printf '...')"):
                local IFS=$'\n'
possible bashism in scripts/kdb-bash-completion line 27 (compgen):
                COMPREPLY=( $( compgen -W '${commands[@]}' -- "${cur}" ) )
possible bashism in scripts/kdb-bash-completion line 33 (alternative test command ([[ foo ]] should be [ foo ])):
        if [[ $pathcommands =~ $prev ]]
possible bashism in scripts/kdb-bash-completion line 35 ($'...' should be "$(printf '...')"):
                local IFS=$'\n'
possible bashism in scripts/kdb-bash-completion line 37 (compgen):
                COMPREPLY=( $( compgen -W '${paths[@]}' -- "${cur}" ) )
possible bashism in scripts/kdb-bash-completion line 43 (bash arrays, ${name[0|*|@]}):
                for entry in ${COMPREPLY[*]}
possible bashism in scripts/kdb-bash-completion line 45 (${foo:3[:1]}):
                        if [[ "${cur:0:1}" == "'" ]]
possible bashism in scripts/kdb-bash-completion line 45 (alternative test command ([[ foo ]] should be [ foo ])):
                        if [[ "${cur:0:1}" == "'" ]]
possible bashism in scripts/kdb-bash-completion line 45 (should be 'b = a'):
                        if [[ "${cur:0:1}" == "'" ]]
possible bashism in scripts/kdb-bash-completion line 50 (${parm/?/pat[/str]}):
                                COMPREPLY[$i]="${entry//\'/${escaped_single_quote}}"
possible bashism in scripts/kdb-bash-completion line 51 (${foo:3[:1]}):
                        elif [[ "${cur:0:1}" == "\"" ]]
possible bashism in scripts/kdb-bash-completion line 51 (alternative test command ([[ foo ]] should be [ foo ])):
                        elif [[ "${cur:0:1}" == "\"" ]]
possible bashism in scripts/kdb-bash-completion line 51 (should be 'b = a'):
                        elif [[ "${cur:0:1}" == "\"" ]]
possible bashism in scripts/kdb-bash-completion line 55 (${parm/?/pat[/str]}):
                                entry="${entry//\\/\\\\}"
possible bashism in scripts/kdb-bash-completion line 56 (${parm/?/pat[/str]}):
                                COMPREPLY[$i]="${entry//\"/\\\"}"
possible bashism in scripts/kdb-bash-completion line 60 (${parm/?/pat[/str]}):
                                entry="${entry//\\/\\\\}"
possible bashism in scripts/kdb-bash-completion line 61 (${parm/?/pat[/str]}):
                                entry="${entry//\'/\'}"
possible bashism in scripts/kdb-bash-completion line 62 (${parm/?/pat[/str]}):
                                entry="${entry//\"/\\\"}"
possible bashism in scripts/kdb-bash-completion line 63 (${parm/?/pat[/str]}):
                                COMPREPLY[$i]="${entry// /\\ }"
possible bashism in scripts/kdb-bash-completion line 65 ('((' should be '$(('):
                        (( i++ ))
possible bashism in scripts/kdb-bash-completion line 73 (complete):
complete -o default -F _kdb kdb
script scripts/kdb_zsh_completion does not appear to have a #! interpreter line;
you may get strange results
possible bashism in scripts/kdb_zsh_completion line 16 (typeset):
    typeset -a paths
possible bashism in scripts/kdb_zsh_completion line 21 ([^] should be [!]):
    slashes=${#PREFIX//[^\\\/]/}
possible bashism in scripts/kdb_zsh_completion line 47 (bash arrays, ${name[0|*|@]}):
        if [[ ${PREFIX[-1]} == "/" ]]; then
possible bashism in scripts/kdb_zsh_completion line 47 (alternative test command ([[ foo ]] should be [ foo ])):
        if [[ ${PREFIX[-1]} == "/" ]]; then
possible bashism in scripts/kdb_zsh_completion line 50 (<<< here string):
            pre=$(cut -d "/" -f -$slashes <<< $PREFIX)
possible bashism in scripts/kdb_zsh_completion line 60 (function names should only contain [a-z0-9_]):
_kdb-check () {
possible bashism in scripts/kdb_zsh_completion line 64 (function names should only contain [a-z0-9_]):
_kdb-convert () {
possible bashism in scripts/kdb_zsh_completion line 68 (function names should only contain [a-z0-9_]):
_kdb-cp () {
possible bashism in scripts/kdb_zsh_completion line 73 (function names should only contain [a-z0-9_]):
_kdb-export () {
possible bashism in scripts/kdb_zsh_completion line 78 (function names should only contain [a-z0-9_]):
_kdb-file () {
possible bashism in scripts/kdb_zsh_completion line 83 (function names should only contain [a-z0-9_]):
_kdb-fstab () {
possible bashism in scripts/kdb_zsh_completion line 88 (function names should only contain [a-z0-9_]):
_kdb-get () { 
possible bashism in scripts/kdb_zsh_completion line 93 (function names should only contain [a-z0-9_]):
_kdb-getmeta () { 
possible bashism in scripts/kdb_zsh_completion line 98 (function names should only contain [a-z0-9_]):
_kdb-import () {
possible bashism in scripts/kdb_zsh_completion line 103 (function names should only contain [a-z0-9_]):
_kdb-info () {
possible bashism in scripts/kdb_zsh_completion line 107 (function names should only contain [a-z0-9_]):
_kdb-list () {
possible bashism in scripts/kdb_zsh_completion line 112 (function names should only contain [a-z0-9_]):
_kdb-ls () {
possible bashism in scripts/kdb_zsh_completion line 117 (function names should only contain [a-z0-9_]):
_kdb-lsmeta () { 
possible bashism in scripts/kdb_zsh_completion line 121 (function names should only contain [a-z0-9_]):
_kdb-merge () {
possible bashism in scripts/kdb_zsh_completion line 125 (function names should only contain [a-z0-9_]):
_kdb-mount () {
possible bashism in scripts/kdb_zsh_completion line 129 (function names should only contain [a-z0-9_]):
_kdb-mv () {
possible bashism in scripts/kdb_zsh_completion line 134 (function names should only contain [a-z0-9_]):
_kdb-remount () { 
possible bashism in scripts/kdb_zsh_completion line 139 (function names should only contain [a-z0-9_]):
_kdb-rm () {
possible bashism in scripts/kdb_zsh_completion line 144 (function names should only contain [a-z0-9_]):
_kdb-set () {
possible bashism in scripts/kdb_zsh_completion line 149 (function names should only contain [a-z0-9_]):
_kdb-setmeta () { 
possible bashism in scripts/kdb_zsh_completion line 154 (function names should only contain [a-z0-9_]):
_kdb-sget () {
possible bashism in scripts/kdb_zsh_completion line 159 (function names should only contain [a-z0-9_]):
_kdb-shell () { 
possible bashism in scripts/kdb_zsh_completion line 164 (function names should only contain [a-z0-9_]):
_kdb-test () {
possible bashism in scripts/kdb_zsh_completion line 169 (function names should only contain [a-z0-9_]):
_kdb-umount () { 
possible bashism in scripts/kdb_zsh_completion line 174 (function names should only contain [a-z0-9_]):
_kdb-vset () {
possible bashism in scripts/kdb_zsh_completion line 179 (function names should only contain [a-z0-9_]):
_kdb-help () { 
possible bashism in scripts/kdb_zsh_completion line 183 (function names should only contain [a-z0-9_]):
_kdb-list-tools () {
possible bashism in scripts/kdb_zsh_completion line 196 (local -opt):
    local -a cmdtypes
possible bashism in scripts/kdb_zsh_completion line 199 (local -opt):
    local -a $cmdtypes
possible bashism in scripts/kdb_zsh_completion line 232 (local -opt):
  local -a aliases
possible bashism in scripts/kdb_zsh_completion line 235 (local -opt):
  local -a allcmds allmatching alts disp expl
possible bashism in scripts/kdb_zsh_completion line 239 (alternative test command ([[ foo ]] should be [ foo ])):
    if [[ $cmdtype = aliases ]]; then
possible bashism in scripts/kdb_zsh_completion line 244 (local -opt):
    local -a ${cmdtype}_m
possible bashism in scripts/kdb_zsh_completion line 246 (should be VAR="${VAR}foo"):
    allcmds+=( ${(P)${:-${cmdtype}_m}} )
possible bashism in scripts/kdb_zsh_completion line 253 (local -opt):
    local -a ${cmdtype}_d
possible bashism in scripts/kdb_zsh_completion line 255 ('((' should be '$(('):
    (( $#disp )) && set -A ${cmdtype}_d \
        ${${(r.COLUMNS-4.)${(P)cmdtype}/(#s)(#m)[^:]##:/${(r.len.)MATCH[1,-2]} $sep }%% #}
possible bashism in scripts/kdb_zsh_completion line 256 (${parm/?/pat[/str]}):
    alts+=( "${cmdtype//_/-}:${${cmdtype//_/ }%%(e|)s}:compadd ${(e)disp} -a ${cmdtype}_m" )
possible bashism in scripts/kdb_zsh_completion line 256 (should be VAR="${VAR}foo"):
    alts+=( "${cmdtype//_/-}:${${cmdtype//_/ }%%(e|)s}:compadd ${(e)disp} -a ${cmdtype}_m" )
script scripts/kdb-zsh-noglob does not appear to have a #! interpreter line;
you may get strange results
script scripts/README.md does not appear to have a #! interpreter line;
you may get strange results
script scripts/update-infos-status does not appear to be a /bin/sh script; skipping
possible bashism in scripts/update-snippet-repository line 37 (unsafe echo with backslash):
  git commit -m "auto-commit: $ELEKTRA_REST_AUTHOR $action entry $ELEKTRA_REST_KEY" -m "$(echo "Title: $ELEKTRA_REST_TITLE\nPlugin: $ELEKTRA_REST_PLUGIN")"
script scripts/zsh does not appear to have a #! interpreter line;
you may get strange results
markus2330 commented 7 years ago

Btw. adding #!/bin/bashas interpreter line is a possible fix, too!

markus2330 commented 7 years ago

@e1528532 can you quickly go through the list and add #/bin/bash where you think actual bash features are wanted?

e1528532 commented 7 years ago

Currently going through the errors, there is a very nice reference in https://wiki.ubuntu.com/DashAsBinSh which explains for a lot of the reported things how they could be done better.

For some of the scripts it was obvious (e.g. bash completion needs bash, zsh completion needs zsh, fish completion needs fish), i've fixed those in #1352 .

Files i fixed which might not be obvious on the first sight:

Unfixed stuff where I'm not sure how to proceed:

There is an option -px which makes the check_bashisms more strict and will yield additional possible problems as echo -n which is different across shells (normal echo is fine though) or the local variable declaration, which behaves differently in dash (basically if you want two local variables you would do local a b in bash, in dash you have to put them on separate lines, so local a\nlocal b. I've fixed those cases.

Also i've replaced occurences of echo -n with a simple printf. echo automatically sends a newline at the end, unless you specify -n, printf doesn't do that by default, so as long as you make no use of printf's formatting features printf "abc" and echo -n "abc" should behave the same as we don't make use of more complicated outputs with echo. And in zsh echo -n does behave differently, here it outputs "asdf%" instead of supressing the newline. Thats why i guess the occurence in zsh is correct as its most likely expected. See https://unix.stackexchange.com/questions/58310/difference-between-printf-and-echo-in-bash .

markus2330 commented 7 years ago
benchmark_augeas_hosts.sh and benchmark_libsplit.sh

bash requirement is no issue here! (Generally in benchmarks: These are not tools everyone needs to run, so also add /bin/bash for benchmark-createtree)

build-homepage

bash also okay here!

split this in two lines, which is unnecessarily verbose, or ignore the warning as its a false positive IMO?

If you can fix all others, please split them so that we are warning-free.

kdb-zsh-noglob, zsh: As its meant to be put in .zshrc or used from within profile.d, and is not an actual script you should execute, i guess its fine.

Yes, but you might want to add /usr/bin/zsh to make the tool happy.

So in matter of doubt, add the bash dependency (+ argumentation why). If it is worthwhile to avoid it, I will say something.