3 ms·
> This requires a GNU xargs that supports NULL termination (or something compatible); as I understand it, this cannot be done with POSIX tools. You can do this
by tczMUFlmoNk 3y ago
> This requires a GNU xargs that supports NULL termination (or something compatible); as I understand it, this cannot be done with POSIX tools.
You can do this with `tr`, right?
#!/bin/dash
for path in /proc/*/cmdline
do
p=${path#*/} p=${p#*/} p=${p%/*}
case "$p" in *[!0-9]*) continue;; esac
c="$(tr '\0' ' ' < "$path" | sed '$s/ $//')"
[ -n "$c" ] && printf %6d\ %s\\n "$p" "$c"
done
Those escape sequences are covered in the standard: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/tr.html https://pubs.opengroup.org/onlinepubs/9699919799/utilities/t...
(But please correct me if I'm missing something!)
This also avoids (POSIX-)undefined behavior with `echo` in case one of the processes' `argv[0]` happens to begin with `-n` or any argument contains a backslash.
- chasil 3y agoI had read elsewhere that POSIX tr was not capable of this, but it appears that I am wrong.