bash script returns that user exists but user does not exist
<p><strong>PLEASE TAKE NOTE OF THE REMARK IN THE CODE AFTER FI!</strong>
For the creation of a user account via the browser i let php shell_exec execute a bash script. Even though i'm certain (by checking /etc/shadow) that the username is not taken the script says it does.
The script as it is now does execute the useradd command and the username appears in the /etc/shadow.
Looks like it executes the useradd before and then checks if the user exists?</p>

<p>php </p>

<pre><code>$command = "sudo ./createclientcert.sh $userName $userPass";
if(shell_exec("$command echo $?") == 0){
echo 1;
}
</code></pre>

<p>Shellscript</p>

<pre><code>#!/bin/bash

newclient () {
getent passwd $1 &gt; /dev/null 2&amp;&gt;1
if [ $? -eq 0 ]; then
echo $?
else
useradd $1
echo $1:$2 | chpasswd   
fi
# PLEASE TAKE NOTE!! funny thing is that when code (that had nothing to do with the account creation and was to be removed) that came after fi is in place it works well. 
}

newclient "$1" "$2"
</code></pre>