简体   繁体   English

Linux Bash Shell 脚本 - 接受 ZDBC11CAA5BDA99F77E6FB4DABD882E 列表

[英]Linux Bash Shell Script - Accept a list of arguments

I'm writing a script that will allow the user to delete other users.我正在编写一个脚本,允许用户删除其他用户。 I would like the user to be able to add a list of users to delete as arguments, but I'm unsure how you let the user add as many arguments as they would like.我希望用户能够将要删除的用户列表添加为 arguments,但我不确定您如何让用户根据需要添加尽可能多的 arguments。 I suppose I would have to make a loop, maybe?我想我必须做一个循环,也许? The rest of the script is ready, but my tiny brain seems to struggle with simple tasks.脚本的 rest 已准备就绪,但我的小脑袋似乎在为简单的任务而苦苦挣扎。

I think you would like this:我想你会喜欢这个:

#!/bin/sh
users=$@
for duser in $@
do
 userdel $duser
 [ $? -eq 0 ] && {
    echo "User $duser deleted successed!"
 }||{
   echo "User $duser deleted failed!"
}
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM