Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to i implement deletion of multiple users in my code. So i have an option as an admin to delete multiple users in 1 command

echo "SELECT $OPTION"   
echo "-------------"   
echo "1- Create username"   
echo "2- Create password"   
echo "3- Delete username"   
echo "4- Exit"   
read -p "enter option 1 2 3 or 4:" option   
case $option in      
1) read -p "Enter username:"        
 adduser $REPLY && echo "Username successfully entered"   ;;      
2) passwd && "Password successfully entered" ;;      
3) read -p "Enter user to be deleted: "         
deluser $REPLY && echo "User deleted"  ;;      
4) exit  ;;         

I got this code to delete multiple users

 read -p "Enter users to be deleted: "  #whitespace-separated list of usernames to be deleted     
 for USER in $REPLY; do         
  deluser $USER && echo "User $USER deleted"       

But how do i implement this in my code, do i use a while loop, can someone tell me what i need to do.

Thank You

share|improve this question

migrated from Dec 7 '10 at 1:17

This question came from our site for professional and enthusiast programmers.

@sean: I think I saw you here earlier today, why'd you change names? – Matti Virkkunen Dec 6 '10 at 19:37
my name is still sean – sean Dec 6 '10 at 19:45
You already have the code already (as posted above). With a "for" loop in it. Why not just continue down the path? – pst Dec 6 '10 at 20:39
Guys, im a noob at unix, ive never done anything like this before, im just doing a self-tutorial of some basics commands, im not really good at programing as you probably can tell, so thats why the obvious may seem difficult for me. But thanks for your help – sean Dec 6 '10 at 22:46

You need to add another option and insert your code in the case statement.

But, first I'd recommend that you read up on bash scripting.

Here is the only link you'll (ever) need:

Regards, jgr

share|improve this answer

The read and for loop can be included in the case statement just as you show it. Here, I show it as a replacement for case 3.

case ...
3) read -p "Enter users to be deleted: "  #whitespace-separated list of usernames to be deleted     
    for USER in $REPLY; do         
        deluser $USER && echo "User $USER deleted"       
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.