From 1516ff1550095acf4a24485adb2e4d041cbf1678 Mon Sep 17 00:00:00 2001 From: Narvin Singh Date: Mon, 4 Jan 2021 14:47:13 -0500 Subject: [PATCH] Feat: Default PID Make the pid parameter default to the PID of the current process. Change the exit code for invalid arguments to a value in the user defined range (see https://tldp.org/LDP/abs/html/exitcodes.html). This may be considered a breaking change, but since the only applications that currently use this script don't rely on this code, I don't think we need to bump the major version for this. --- rpid | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/rpid b/rpid index b1f2b71..fb733d0 100755 --- a/rpid +++ b/rpid @@ -3,7 +3,8 @@ USAGE=' USAGE: rpid [=login] - pid The PID of the process for which you want to find the root PID. + pid The PID of the process for which you want to find the root + PID. Defaults to $$. root_name The name (not command line) of the root process, for which @@ -20,16 +21,16 @@ EXAMPLES: Get the PID of the login process that is the ancestor of the current process. - rpid $$ + rpid ' # Validate the arguments -if [[ "$#" -lt 1 || "$#" -gt 2 ]]; then +if [[ "$#" -gt 2 ]]; then printf '%s' "${USAGE}" 1>&2 - exit 128 + exit 64 fi -pid="$1" +pid="${1:-$$}" # Check if the user needs help if [[ "${pid}" =~ ^(-h|-(-)?help)$ ]]; then