I have written a shell script which allows me to create a user and assign them to a group but I keep getting the error line 19: syntax error: unexpected end to file
What am I doing wrong? Would it be possible someone could help me re structure the code to eliminate this problem.
Here is my shell script.
#!/bin/bash
username="U"
group="G"
while [ $username"U" ] >/dev/null 2>&1;
read -p "Please input the username you would like to generate"
if
id -U $username >/dev/null 2&1;
echo 'User already exists"
while [ $group >dev/null 2>&1;
echo "group exists"
else
groupadd $group
fi
while [ condition ]; do...
statements need closure withdone
.if [ condition ]
statement needs to be flowed bythen
keyword. It is not implied. – MelBurslan Mar 22 '16 at 20:46./myscript username groupname
and then in your script use"$1"
for the username and"$2"
for the group name. Note the use of double-quotes around the$1
and$2
variables. it's good practice to (almost) always quote your variables (except in certain special cases which there's no need to go into now), especially if the variable's value is provided by a user in any way (e.g. via command-line args or prompted input). – cas Mar 23 '16 at 02:27