shell script gives error [: !-z: unary operator expected while execute
There are three issues I can see:


The first line should be #!/bin/bash (which together with chmod pkill.sh will allow you to run ./pkill.sh mongod directly)
Whitespace is important in bash, try [ ! -z "$pro" ] :-)
-z tests for an empty string, so ! -z tests for a non-empty one. Ignoring for a moment that -n does the same thing: shouldn't you call kill if the string is non-empty?


PS: Also, using pgrep or even pkill instead of the pipes will make things a lot easier here.