21
#!/bin/bash

names= find /home/devuser -name 'BI*'
echo $names

for name in {names[@]}
do    
 echo $name
 $var = $var$name   
done

echo $var
1
  • 1
    And what is your question?
    – rzymek
    Commented Dec 17, 2013 at 9:35

2 Answers 2

29
#!/bin/bash

names= find /home/devuser -name 'BI*'
echo $names

for name in {names[@]}
do    
 echo $name
 var=$var$name //$ should be removed which is prefixed before var. Blank space before and after equal sign should be removed to run this code.   
done

echo $var
4
  • 1
    Are you sure is correct to use sigil in front of the variable name on the left side of an assignment? Anyway, better review your entire post, starting with that comment.
    – manatwork
    Commented Dec 17, 2013 at 9:27
  • Better. :) Now the comment. Then executing and capturing find's output. Then the array variable in the for's in clause.
    – manatwork
    Commented Dec 17, 2013 at 9:31
  • 1
    The final point will probably be that is better to use no loop: var="$(IFS=; echo "${names[*]}")". So unless you wish to teach the question owner, there is no much benefit in correcting his multiple syntax errors.
    – manatwork
    Commented Dec 17, 2013 at 9:41
  • 2
    You forgot a $, the for loop line should read for name in ${names[@]}
    – bcattle
    Commented Sep 3, 2014 at 5:36
7

Change

$var = $var$name   

to

var=$var$name   

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