Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Bash Array

Status
Not open for further replies.

FinnMan

Technical User
Feb 20, 2001
75
US
I'm going batty with this seemingly simple array. What I'm trying to do is cat a file and do some ldap lookups.

What I've done is this:
**************************

wUSERS1=`cat usersample | awk -F "/" '{print $5}'\n`;
for h in "${wUSERS1[@]}"
do
echo "$h"

done
**************************
The above works absolutely fine, no problems. I've having issues when I do the following:
**************************


wUSERS1=`cat usersample | awk -F "/" '{print $5}'\n`;
for h in "${wUSERS1[@]}"
do
ldaplookup "$h"
done

**************************

ldaplookup is a bash script I wrote to do queries. I use the script all the time with no problems so I know it works ok. However, doing the above does not work for EACH element in the array. It stops after the first one! I've tried single quotes, double quotes, while statements, and everything else I can think of but I can get the script to perform for each element.

Can someone toss this dog a bone?

Best Regards,
FM
 

did you realize: awk, sed, cat, lp[r], more ... most of *nix
tool are able to oprn files
so
wUSERS1=`cat usersample | awk -F "/" '{print $5}'`
and
wUSERS1=`awk -F "/" '{print $5}' usersample`
are the same ?

the '\n' is not needed so the ';'

look (for this exemple) to faster tools: cut, sed... g.e:
cut -d/ -f5
 
Have you tried something like this ?
while IFS="/" read f1 f2 f3 f4 f5 buf
do ldaplookup "$f5"
done<usersample

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Wow...that 'while' works just great! Thx a million. Also, thx for the tips with Awk.

Can you explain the statement to me? I'm not sure I understand:

while IFS="/"

"done" I understand. done< I haven't seen before either....


Best Regards,
FM
 
In your bash man (or info) page, take a look at I/O redirection (for the <) and at builtin (or special) shell variables (for IFS).

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top