0

How to I implement deletion of multiple users in my code. So Ihave an option as an admin to delete multiple users in 1 command:

#!/bin/bash
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  ;;         
esac

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"       
done;;

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

4
  • 2
    @sean: I think I saw you here earlier today, why'd you change names? Dec 6, 2010 at 19:37
  • my name is still sean
    – sean
    Dec 6, 2010 at 19:45
  • 1
    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, 2010 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, 2010 at 22:46

1 Answer 1

0

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"       
    done;;

You must log in to answer this question.