我正在尝试创建一个脚本,该脚本将杀死一个进程并在发出 kill -9 命令之前确认该进程正在运行,我遇到了一个错误,它总是假设有输出。
#!/bin/sh
rc=$?
#Ask to check for a process to kill
clear
echo "Please enter a process number you would like to kill"
echo ""
read proc
ps -ef | awk '{print $2}' | grep *$proc*
if [[ $rc != 0 ]]; then
echo "Process not running or already killed"
sleep 2
exit $rc
else
clear
echo "Killing process..."
sleep 2
# kill -9 $proc
fi