Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

#!/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.

Thank You

share|improve this question

migrated from stackoverflow.com Dec 7 '10 at 1:17

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

2  
@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
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 '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
add comment

2 Answers 2

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: http://tldp.org/LDP/abs/html/

Regards, jgr

share|improve this answer
add comment

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;;
share|improve this answer
add comment

Your Answer

 
discard

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