From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id QKPcK6fx5mcJyx0AWB0awg (envelope-from ) for ; Fri, 28 Mar 2025 14:59:51 -0400 Received: by simark.ca (Postfix, from userid 112) id B10E81E0C3; Fri, 28 Mar 2025 14:59:51 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 511DA1E0C0 for ; Fri, 28 Mar 2025 14:59:51 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 01B3D385781B for ; Fri, 28 Mar 2025 18:59:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 01B3D385781B Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) by sourceware.org (Postfix) with ESMTP id ED9123830602 for ; Fri, 28 Mar 2025 18:59:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ED9123830602 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gentoo.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gentoo.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org ED9123830602 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:470:ea4a:1:5054:ff:fec7:86e4 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1743188358; cv=none; b=RhSZvpVECM4Pbi/aRKWoKotkKOLH2NzB+J635pwieAPuzzsLO0o20VxpfubUXXkfhe7n2YDijQljoZylVmSckPL5pbgarm9h3CL1RVEweEUgQyt5xidQZGg4QWvQ34R5H5Vf2GDug6Wr/+Bwtlrc4mblmqhPBlcYguX+0vaKuqM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1743188358; c=relaxed/simple; bh=yTuTPar2XZP9fRhJG05upaK2Ya2Wy6UvoMENeLWhwEY=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=deV3mJ7HChVdLhhN2wwKcibW8RMCuBoTCd+Nadd0F4Vkhk0+Ld45Cc/u3OFABIqIQcDjpLZhr5ETRHKpV39ohXd7PNJ5RbzVtLAPJxZSKtJgGH6UjRlMlwHYRlX+lly2kmnW3W4oGOuLsuHk9wiINCCeZo0ljuYJm0BoVK8lOUI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED9123830602 Received: from mop.. (unknown [82.8.138.118]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: sam@gentoo.org) by smtp.gentoo.org (Postfix) with ESMTPSA id B92B3343138; Fri, 28 Mar 2025 18:59:16 +0000 (UTC) From: Sam James To: gdb-patches@sourceware.org Cc: Simon Marchi , Sam James Subject: [PATCH 1/2] gcore: improve shell use Date: Fri, 28 Mar 2025 18:58:51 +0000 Message-ID: <6be92d7ddcd426fd79a3fb9f44c49abea6e16aef.1743188332.git.sam@gentoo.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.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