Useradd command not found in expect shebang

Hi Team,

I am using shell script to add user and update password automatically.Below is my shell script.


set timeout 120

useradd rock

spawn passwd rock

expect {
“Enter new UNIX password:” { send “rock@123\r” }

expect eof

When i run that script its throwing an error.

[root@WEBPORTALSEA ~]# ./

invalid command name “useradd”

while executing "useradd rock"

(file "./" line 3)

Please let us know how to resolve. I am using RHEL 6.8 Version

echo 'Digite o nome do usuário:'
read user

if [ -n "$user" ]; then
	adduser $user


Thanks for your reply. May i know the meaning of -n “$user” exactly what this command will do


Actually it is not a command is only a check if the variable “$user” has some value avoiding mistakes when you run the command “adduser”