From: Sam James <sam@gentoo.org>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simark@simark.ca>, Sam James <sam@gentoo.org>
Subject: [PATCH 1/2] gcore: improve shell use
Date: Fri, 28 Mar 2025 18:58:51 +0000 [thread overview]
Message-ID: <6be92d7ddcd426fd79a3fb9f44c49abea6e16aef.1743188332.git.sam@gentoo.org> (raw)
In-Reply-To: <cover.1743188332.git.sam@gentoo.org>
* Use bash tests, i.e. '[[' and ']]', instead of POSIX '[' and ']' or
'test' which have their own pitfalls, given gcore has a bash shebang already.
* Use $() subshell syntax rather than `backticks`.
---
gdb/gcore-1.in | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/gdb/gcore-1.in b/gdb/gcore-1.in
index c0979a51db3..edd807b86dc 100644
--- a/gdb/gcore-1.in
+++ b/gdb/gcore-1.in
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
-# Copyright (C) 2003-2024 Free Software Foundation, Inc.
+# Copyright (C) 2003-2025 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -64,7 +64,7 @@ function print_version() {
}
while getopts vhao:d:-: OPT; do
- if [ "$OPT" = "-" ]; then
+ if [[ "$OPT" = "-" ]]; then
OPT="${OPTARG%%=*}"
OPTARG="${OPTARG#'$OPT'}"
OPTARG="${OPTARG#=}"
@@ -111,7 +111,7 @@ done
shift $((OPTIND-1))
-if [ "$#" -eq "0" ]
+if [[ "$#" -eq "0" ]]
then
print_usage 1>&2
exit 1
@@ -119,19 +119,19 @@ fi
# Attempt to fetch the absolute path to the gcore script that was
# called.
-binary_path=`dirname "$0"`
+binary_path=$(dirname "$0")
-if test "x$binary_path" = x. ; then
+if [[ $binary_path == x. ]] ; then
# We got "." back as a path. This means the user executed
# the gcore script locally (i.e. ./gcore) or called the
# script via a shell interpreter (i.e. sh gcore).
- binary_basename=`basename "$0"`
+ binary_basename=$(basename "$0")
# If the gcore script was called like "sh gcore" and the script
# lives in the current directory, "which" will not give us "gcore".
# So first we check if the script is in the current directory
# before using the output of "which".
- if test -f "$binary_basename" ; then
+ if [[ -f "$binary_basename" ]]; then
# We have a local gcore script in ".". This covers the case of
# doing "./gcore" or "sh gcore".
binary_path="."
@@ -139,14 +139,14 @@ if test "x$binary_path" = x. ; then
# The gcore script was not found in ".", which means the script
# was called from somewhere else in $PATH by "sh gcore".
# Extract the correct path now.
- binary_path_from_env=`which "$0"`
- binary_path=`dirname "$binary_path_from_env"`
+ binary_path_from_env=$(which "$0")
+ binary_path=$(dirname "$binary_path_from_env")
fi
fi
# Check if the GDB binary is in the expected path. If not, just
# quit with a message.
-if [ ! -f "$binary_path/@GDB_TRANSFORM_NAME@" ]; then
+if [[ ! -f "$binary_path/@GDB_TRANSFORM_NAME@" ]]; then
echo "gcore: GDB binary (${binary_path}/@GDB_TRANSFORM_NAME@) not found"
exit 1
fi
@@ -166,7 +166,7 @@ do
"${dump_all_cmds[@]}" \
-ex "attach $pid" -ex "gcore $prefix.$pid" -ex detach -ex quit
- if [ -r "$prefix.$pid" ] ; then
+ if [[ -r "$prefix.$pid" ]] ; then
rc=0
else
echo "@GCORE_TRANSFORM_NAME@: failed to create $prefix.$pid"
--
2.49.0
next prev parent reply other threads:[~2025-03-28 18:59 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-28 18:58 [PATCH 0/2] shell fixes for gcore, gdb-add-index Sam James
2025-03-28 18:58 ` Sam James [this message]
2025-03-29 23:42 ` [PATCH 1/2] gcore: improve shell use Keith Seitz
2025-03-31 18:26 ` Simon Marchi
2025-03-31 18:44 ` Andreas Schwab
2025-03-31 18:54 ` Simon Marchi
2025-04-02 16:08 ` Keith Seitz
2025-04-01 13:39 ` Tom Tromey
2025-04-02 16:15 ` Simon Marchi
2025-04-02 20:31 ` Tom Tromey
2025-03-28 18:58 ` [PATCH 2/2] gdb-add-index: fix shellcheck warnings Sam James
2025-03-29 23:42 ` Keith Seitz
2025-03-31 18:30 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6be92d7ddcd426fd79a3fb9f44c49abea6e16aef.1743188332.git.sam@gentoo.org \
--to=sam@gentoo.org \
--cc=gdb-patches@sourceware.org \
--cc=simark@simark.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox