From: Samir Mulani <sa...@linux.vnet.ibm.com>

Fixed the shellcheck warnings in buildid.sh, record+probe_libc_inet_pton.sh
and record+script_probe_vfs_getname.sh perf shell scripts:

1. Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
2. Prefer [ p ] || [ q ] as [ p -o q ] is not well defined.
3. Used * argument to avoid the argument mixes string and array
4. Resolved issue for variable refernce, where the variable is
   being used before it has been initialized.
5. Resolved word splitting issue (syntax error).
6. The "err" variable has been removed from buildid.sh since
   it is not used anywhere in the code.

Signed-off-by: Athira Rajeev <atraj...@linux.vnet.ibm.com>
Signed-off-by: Kajol Jain <kj...@linux.ibm.com>
Signed-off-by: Samir Mulani <sa...@linux.vnet.ibm.com>
---
 tools/perf/tests/shell/buildid.sh                    | 12 ++++++------
 .../perf/tests/shell/record+probe_libc_inet_pton.sh  |  6 +++---
 .../tests/shell/record+script_probe_vfs_getname.sh   |  4 ++--
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/tools/perf/tests/shell/buildid.sh 
b/tools/perf/tests/shell/buildid.sh
index 0ce22ea0a7f1..3383ca3399d4 100755
--- a/tools/perf/tests/shell/buildid.sh
+++ b/tools/perf/tests/shell/buildid.sh
@@ -83,12 +83,12 @@ check()
        # in case of pe-file.exe file
        echo $1 | grep ".exe"
        if [ $? -eq 0 ]; then
-               if [ -x $1  -a ! -x $file ]; then
+               if [ -x $1 ] && [ ! -x $file ]; then
                        echo "failed: file ${file} executable does not exist"
                        exit 1
                fi
 
-               if [ ! -x $file -a ! -e $file ]; then
+               if [ ! -x $file ] && [ ! -e $file ]; then
                        echo "failed: file ${file} does not exist"
                        exit 1
                fi
@@ -136,10 +136,10 @@ test_record()
        log_err=$(mktemp /tmp/perf.log.err.XXX)
        perf="perf --buildid-dir ${build_id_dir}"
 
-       echo "running: perf record $@"
-       ${perf} record --buildid-all -o ${data} $@ 1>${log_out} 2>${log_err}
+       echo "running: perf record $*"
+       ${perf} record --buildid-all -o ${data} "$@" 1>${log_out} 2>${log_err}
        if [ $? -ne 0 ]; then
-               echo "failed: record $@"
+               echo "failed: record $*"
                echo "see log: ${log_err}"
                exit 1
        fi
@@ -172,4 +172,4 @@ if [ ${run_pe} -eq 1 ]; then
        rm -r ${wineprefix}
 fi
 
-exit ${err}
+exit 0
diff --git a/tools/perf/tests/shell/record+probe_libc_inet_pton.sh 
b/tools/perf/tests/shell/record+probe_libc_inet_pton.sh
index bbb5b3d185fa..0934fb0cd68f 100755
--- a/tools/perf/tests/shell/record+probe_libc_inet_pton.sh
+++ b/tools/perf/tests/shell/record+probe_libc_inet_pton.sh
@@ -10,8 +10,8 @@
 # SPDX-License-Identifier: GPL-2.0
 # Arnaldo Carvalho de Melo <a...@kernel.org>, 2017
 
-. $(dirname $0)/lib/probe.sh
-. $(dirname $0)/lib/probe_vfs_getname.sh
+. "$(dirname "$0")/lib/probe.sh"
+. "$(dirname "$0")/lib/probe_vfs_getname.sh"
 
 libc=$(grep -w libc /proc/self/maps | head -1 | sed -r 
's/.*[[:space:]](\/.*)/\1/g')
 nm -Dg $libc 2>/dev/null | fgrep -q inet_pton || exit 254
@@ -23,7 +23,7 @@ add_libc_inet_pton_event() {
        event_name=$(perf probe -f -x $libc -a inet_pton 2>&1 | tail -n +2 | 
head -n -5 | \
                        grep -P -o "$event_pattern(?=[[:space:]]\(on inet_pton 
in $libc\))")
 
-       if [ $? -ne 0 -o -z "$event_name" ] ; then
+       if [ $? -ne 0 ] || [ -z "$event_name" ] ; then
                printf "FAIL: could not add event\n"
                return 1
        fi
diff --git a/tools/perf/tests/shell/record+script_probe_vfs_getname.sh 
b/tools/perf/tests/shell/record+script_probe_vfs_getname.sh
index 1341437e1bd9..7f664f1889d9 100755
--- a/tools/perf/tests/shell/record+script_probe_vfs_getname.sh
+++ b/tools/perf/tests/shell/record+script_probe_vfs_getname.sh
@@ -9,11 +9,11 @@
 # SPDX-License-Identifier: GPL-2.0
 # Arnaldo Carvalho de Melo <a...@kernel.org>, 2017
 
-. $(dirname $0)/lib/probe.sh
+. "$(dirname "$0")/lib/probe.sh"
 
 skip_if_no_perf_probe || exit 2
 
-. $(dirname $0)/lib/probe_vfs_getname.sh
+. "$(dirname "$0")/lib/probe_vfs_getname.sh"
 
 record_open_file() {
        echo "Recording open file:"
-- 
2.39.1

Reply via email to