Create a user account
This Bash script creates a user account if no arguments are passed, or deletes a user account if "del" and the username are passed as arguments.
#! /usr/bin/bash
if [ -z "${1}" ]
then
echo "What is your intended username?"
read username
echo "What is your password"
read password
#A user can be passed in as a command line argument
echo "$username user account being created."
#A user is created with the name of command line argument
sudo useradd -m $username
#A password can be parsed in as a command line argument.
sudo chpasswd <<< $username:$password
sleep 2
echo "If you want to delete the user then pass 'del' and username in command line argument. e.g: ./create-user.sh del username"
else
sudo userdel -rf "${2}"
sleep 2
echo "${2} user account successfully deleted."
exit 0
fi
In this specific case, the condition checks whether the length of the first command line argument (represented by the $1 variable) is zero or not. If it is zero, then the script assumes that no arguments were passed, and proceeds to prompt the user to input a username and password to create a new user account. Otherwise, it assumes that the first argument is "del", and proceeds to delete the user account specified by the second argument.