bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ldapscripts unusable from within a 'while read line' loop


From: Chris F.A. Johnson
Subject: Re: ldapscripts unusable from within a 'while read line' loop
Date: Thu, 1 Aug 2013 10:15:58 -0400 (EDT)
User-agent: Alpine 2.00 (LMD 1167 2008-08-23)

On Thu, 1 Aug 2013, Lakshminarasimhan Srinivasan wrote:
...
Description:
ldapscripts do not work from inside a "while read line" loop. The exact same scripts were working fine until the last upgrade

Repeat-By:
Prerequisite: ldapscripts installed.
Open a new bash script and type in the following:
-------------------------------------------------
#!/bin/bash
echo "Testing if it works outside of the loop"
ldapid
echo "Getting into the read line loop"
while read line
do
 ldapid
done <"Some file"
------------------------------------------------
The 'ldapid' command, which works outside of the loop, does not work from within. This time it throws an error "Cannot guess user". Now we check an alternative:
Create a new script and type in the following:
------------------------------------------------
#!/bin/bash
echo "Testing if it works outside of the loop"
ldapid
readarray lines < "some file"
echo "Getting into the for loop"
for line in "${lines[@]}"
do
 ldapid
done
-----------------------------------------------
In this case 'ldapid' works both times. In fact, ldapid works in every other loop except a 'while read line' and I really do not have any idea why.

  I have no idea what ldapid is or does (I can't find it for my
  system), but perhaps it reads from stdin? If it does, it will be
  reading from the file.

--
   Chris F.A. Johnson, <http://cfajohnson.com/>
   Author:
   Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]