reversed course a bunch but better psfind approach
authorChris Koeritz <fred@gruntose.com>
Sun, 29 May 2022 12:51:49 +0000 (08:51 -0400)
committerChris Koeritz <fred@gruntose.com>
Sun, 29 May 2022 12:51:49 +0000 (08:51 -0400)
made it just use awk to pluck out the fields, so we didn't need a lot of ugly escaped stuff trying to make a command line that would de-escape the right way at the right time.

scripts/core/functions.sh

index 24ce6e8c56fb7b987872a78559cc19cc8a411167..6083bc7186d0fb072864efe6f4a4f22819aacc9a 100644 (file)
@@ -293,15 +293,18 @@ if [ -z "$skip_all" ]; then
       # gets cygwin's (god awful) ps to show windoze processes also.
       local EXTRA_DOZER_FLAGS="-W"
       # pattern to use for peeling off the process numbers.
-      local pid_finder_pattern='s/ *\([0-9][0-9]*\) *.*$/\1/p'
-
+#      local pid_finder_cmd="awk -- '{ print \$4; }'"
+      local field_number=4
     else
       # flags which clean up the process listing output on unixes.
       # apparently cygwin doesn't count as a type of unix, because their
       # crummy specialized ps command doesn't support normal ps flags.
       local EXTRA_UNIX_FLAGS="-o pid,args"
       # pattern to use for peeling off the process numbers.
-      local pid_finder_pattern='s/^[[:space:]]*\([0-9][0-9]*\).*$/\1/p'
+#      local pid_finder_cmd="sed -n -e \\'s/^[[:space:]]*\([0-9][0-9]*\).*$/\\\\1/p\\'"
+#echo pidfinder: $pid_finder_cmd
+#      local pid_finder_cmd="awk -- '{ print \$1; }'"
+      local field_number=1
     fi
 
     /bin/ps $EXTRA_DOZER_FLAGS $EXTRA_UNIX_FLAGS $user_flag | tail -n +2 >$PID_DUMP
@@ -318,7 +321,7 @@ if [ -z "$skip_all" ]; then
       PIDS_SOUGHT+=($(cat $PID_DUMP \
         | grep -i "$i" \
         | grep -v "$excluder" \
-        | sed -n -e "$pid_finder_pattern"))
+        | awk -- "{ print \$${field_number}; }" ))
     done
 #echo ====
 #echo pids sought list became: