The
processSnapshotwill always be empty: the ps output is going to the filewhen you pass the pattern as a variable, use the pattern match operator:
findProcess=$( awk -v pname="$findProcessName" '$0 ~ pname' $tempFile )only use backticks when you need the output of a command. This
rm $tempFile`rm $tempFile`executes the rm command, returns the output back to the shell and, it the output is non-empty, the shell attempts to execute that output as a command.
$ `echo foo` bash: foo: command not found $ `echo whoami` jackmanRemove the backticks.
Of course, you don't need the temp file at all:
pgrep -fl $findProcessName