Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am a newbie in Unix. I have a requirement in which I have to put the output of find statement in array because later in the script I have to use the output lines one by one. My find statement will retrieve me the location of directories based on the condition.

Here are the find statements:

find blah -mindepth 3 -maxdepth 3 -type d  -regex ".*/V[0-9]+/wsdls+" 
share|improve this question
i got a solution for this.. array=($(find blah -mindepth 3 -maxdepth 3 -type d -regex ".*/V[0-9]+/wsdls+")) i=0 for file in "${array[@]}" do echo "${file}" let i++ done but here the strange thing is after executing this though i am able to see data properly but in every line it's saying i++ is not a valida command..and as soon as i removed the i++, then it gave me the data question is how it is happening as we are not increasing the value of i.. – Ankit Apr 20 '11 at 12:10
If you found an answer, please post it as an actual answer and not a comment. – Wuffers Apr 20 '11 at 12:20
hard to give you help when we can't see the newlines in your code. Please put it in an answer. – glenn jackman Apr 20 '11 at 13:21

You can do this:

array=( $(find blah -mindepth 3 -maxdepth 3 -type d -regex ".*/V[0-9]+/wsdls+") )

# loop over it
for i in ${array[@]}
    echo $i

# or in a while loop
while [ $i -lt ${#array[@]} ]
    echo $i: ${array[$i]}
share|improve this answer
You'll need to set IFS=$'\n' first though: in case any of the filenames have spaces, you want to keep them as a single array element. The you'll also want to use double quotes when referencing the array: for i in "${array[@]}" – glenn jackman Apr 20 '11 at 13:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .