Checking a Varaible

This is a part of my shell...

echo -n "PID: "
set tmpPID = $<
echo -n "Signal (KILL/STOP): "
set tmpSig = $<
???????
kill -$tmpSig $tmpPID

How can I check tmpPID is numeric and there is whether a process with the PID before kill?

or probably say, how to check whether it is a integer?

/-----------------------------/

To test if a value is numeric you can do :

if expr "$value" : '[0-9]\+$' >/dev/null
??echo "Numeric value"
??echo "Not numeric value"
fi

With ksh, you can also do :

if [[ "$value" = +([0-9]) ]]

/-----------------------------/

How about checking of PID?

You can try something like this :

if [ -n "`ps -e | awk "\$1==$PID" ]
??then echo "PID found"
??else echo "PID not found"
fi

assume that 'ps -e' display pid in col 1

Have a Unix Problem
Unix Forum - Do you have a UNIX Question?

Unix Books :-
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Return to : - Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.