简单的一个shell 有兴趣的可以看看,纯粹自娱自乐 #! /bin/bash #This script function is display OS pid list by used command ps lspids() { #HEAD=false #USAGE="Usage: $0 [-h] process" # #if [ $1 = "-h" ];then # HEAD=true # shift #fi #if [ "$HEAD" = "true" ] ;then #echo "in head" # ps -ef | head -1 #fi #echo #if [ -z $1 ];then # echo $USAGE # return 1 #else # ps -ef | grep "$1" | grep -v grep #fi echo "in lspids" USAGE="Usage: $0 [-h|-s] process"; HEAD=false; SORT=false; PSCMD="/bin/ps -ef "; SORTCMD="/bin/sort -rn"; for OPT in $@ do case "$OPT" in -h) HEAD=true; shift ;; -s) SORT=true; shift ;; _*) echo $USAGE; return 1; ;; esac done echo "head :$HEAD /t sort :$SORT /$1 :$1" if [ -z "$1" ];then echo $USAGE; return 1; fi if [ "$HEAD" = "true" ]; then $PSCMD 2> /dev/null | head -1 fi if [ "$SORT" = "true" ]; then $PSCMD 2>/dev/null | grep "$1" | grep -v grep | $SORTCMD else $PSCMD 2>/dev/null | grep "$1" | grep -v grep fi } #main echo "begin" lspids $@ echo "end"