I must be a bit confused because your second program is completely different from the first. You also call the argument userid and then use a user name for it. Here is a version which takes a name for an argument and returns whether the associated uid is 0.
foo=`grep "^$1:" /etc/passwd | cut -f 3 -d :`
if [ x"$foo" = x ]; then
echo User $1 not found
if [ `grep "^$1:" /etc/passwd | cut -f 3 -d :` -eq 0 ]; then
echo $1 has uid equal to zero.
I'm not really sure if that's what you want.
I'm also not sure what you mean by the "same error" because my last version is not going to give
[ninja: command not found
, since [ is not next to $1
edit: I got distracted while writing that and there were 2 replies posted between when I started and finished