21
#!/bin/bash

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

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

echo $var
bahamat
  • 39,666
  • 4
  • 75
  • 104
jagan
  • 251

2 Answers2

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
Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
Ruban Savvy
  • 8,659
  • 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 Dec 17 '13 at 09:27
  • Better. :) Now the comment. Then executing and capturing find's output. Then the array variable in the for's in clause. – manatwork Dec 17 '13 at 09: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 Dec 17 '13 at 09:41
  • 2
    You forgot a $, the for loop line should read for name in ${names[@]} – bcattle Sep 03 '14 at 05:36
7

Change

$var = $var$name   

to

var=$var$name   
rzymek
  • 531