UNIX Programming, Certification, System Administration, Performance Tuning Reference Books
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

Quick Links:
Do you have a UNIX Question?

Unix Home: Unix System Administration Hints and Tips