You need to use echo
(or printf
) to actually put the value of $LINE
onto the standard input of the awk
command.
LINE=$(ps aux | grep "$1")
PROCESS=$(echo "$LINE" | awk '{print $2}')
echo $PROCESS
kill -9 $PROCESS
There's no need use LINE
; you can set PROCESS
with a single line
PROCESS=$(ps aux | grep "$1" | awk '{print $2}')
or better, skip the grep
:
PROCESS=$(ps aux | awk -v pname="$1" '$1 ~ pname {print $2}')
Finally, don't use kill -9
; that's a last resort for debugging faulty programs. For any program that you didn't write yourself, kill "$PROCESS"
should be sufficient.