Skip to content

Instantly share code, notes, and snippets.

@wx13
Created July 19, 2010 22:18
Show Gist options
  • Save wx13/482132 to your computer and use it in GitHub Desktop.
Save wx13/482132 to your computer and use it in GitHub Desktop.
kill jobs easily
#!/bin/bash
str=$1
list=$(ps -asW | grep ${str})
#list=$(ps -asW | grep ${str} | awk '{print "[" NR "]", $0}')
OLDIFS=${IFS}
IFS=`echo -en "\n\b"`
i=0
for line in ${list}
do
i=$((i+1))
echo "[$i]" ${line}
arr[i]=$(echo ${line} | awk '{print $1}')
done
echo -n ": "
read ans
if [ "${ans}" -gt "0" ] && [ "${ans}" -le "$i" ]
then
/bin/kill -f ${arr[${ans}]}
else
echo "I don't like you."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment