The command substitution is performed before the test take places, so that it actually is something like:
if [ ! -z 1222 1223 1224 1225 1230 1232 1234 1236 1237 1238 1975 1979 1980 1981 ] ; then
This should throw an error for too many arguments or binary operator expected. Anyway, what you really need is
if pgrep bash; then
that checks the exit status of the pgrep command: when processes are found the exit status is 0 (success) and the test is true, when processes don't exist, the exit status is 1 (failure) and the test is false. Anyway, I cannot explain why your test doesn't throw an error message and returns always false.
Moreover note that ! -z
is the same as -n
(the length of string is nonzero).