Bash 命令返回一个列表,应该进行解析

Bash 命令返回一个列表,应该进行解析,bash,for-loop,foreach,while-loop,do-while,Bash,For Loop,Foreach,While Loop,Do While,我有一个shell程序,它返回一个列表: list-all-my-users.sh 结果是: username1 username2 username3 username4 username5 现在我想在另一个程序中使用这个结果 ldapsearch -D "adminuser" -w "password" -p 389 -h server.domain.de -b "DC=ORG,DC=com" -s sub "(&(objectclass=person)(cn=<USERN

我有一个shell程序,它返回一个列表:

list-all-my-users.sh
结果是:

username1
username2
username3
username4
username5
现在我想在另一个程序中使用这个结果

ldapsearch -D "adminuser" -w "password" -p 389 -h server.domain.de -b "DC=ORG,DC=com" -s sub "(&(objectclass=person)(cn=<USERNAME))" | grep employeeID: | awk '{print $2}'
使用while循环

while read username
do
ldapsearch -D "adminuser" -w "password" \
           -p 389 -h server.domain.de \
           -b "DC=ORG,DC=com" \
           -s sub "(&(objectclass=person)(cn=${username}))" | 
           awk '/employeeID:/{print $2}'
done<list-all-my-users.sh
读取用户名时
做
ldapsearch-D“管理员用户”-w“密码”\
-p389-h server.domain.de\
-b“DC=ORG,DC=com”\
-s sub“(&(objectclass=person)(cn=${username}))”|
awk'/employeeID:/{print$2}'
完成
while read username
do
ldapsearch -D "adminuser" -w "password" \
           -p 389 -h server.domain.de \
           -b "DC=ORG,DC=com" \
           -s sub "(&(objectclass=person)(cn=${username}))" | 
           awk '/employeeID:/{print $2}'
done<list-all-my-users.sh