9
rated 0 times
[
9]
[
0]
/ answers: 1 / hits: 937
/ 2 Years ago, tue, july 12, 2022, 12:27:14
I have a simple shell script to check if the user exist, if not, add that user
#!/usr/bin/bash
echo "Enter user"
read -r user
if [ "$(id -u "$user" &>/dev/null)" = 1 ]; then
echo "user existed"
else
useradd "$user"
echo "add password"
passwd "$user"
echo "$user" &>>text.txt
echo "saved"
fi
But it does not display the "echo user exist"
. instead it displays like so:
Enter user
abcdef
useradd: user 'abcdef' already exists
add password
New password:
In this case abcdef
is an existing user
Please let me know what goes wrong here, thanks a lot.
More From » scripts