Skip to content

Instantly share code, notes, and snippets.

@benok
Last active April 9, 2021 22:08
Show Gist options
  • Save benok/3c9715c8d6a66a0171f6a3d3c287cd25 to your computer and use it in GitHub Desktop.
Save benok/3c9715c8d6a66a0171f6a3d3c287cd25 to your computer and use it in GitHub Desktop.
Enable "ps [-p] PID" for /bin/ps from busybox (like Alpine Linux)
#!/bin/sh
# enable "ps [-p] PID" for /bin/ps from busybox (like Alpine)
# copy this script as /usr/local/bin/ps or /usr/bin/ps, and chmod 755 it.
if [ $# == 1 ]; then
echo $1 | grep -q -E '^[0-9]+$' # number only argument
if [ $? == 0 ]; then
OPT_P=1
ARG_P=$1
fi
else
for OPT in "$@"
do
case "$OPT" in
'-p')
OPT_P=1
ARG_P=$2
shift 2
;;
esac
done
fi
if [ x$OPT_P == x1 ]; then
/bin/ps -o pid | grep -q $ARG_P # grep pid only
RET=$?
/bin/ps | egrep "^(PID| *$ARG_P )" # show output like normal ps
exit $RET
else
/bin/ps $*
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment