how to use for loop inside a echo statement in shell script

Mahesh Kalakattu :

I need Your help, I'm getting set of filenames using

for fn in "${fnames[@]}"
  do
   echo $fn;
 done

i need output like

const route=[{
     {name:'filename1',
      component:filename1,
      path:'/filename1'
  }]

I'm trying like this

echo 'const routes=[
      for i in '${fnames[@]}'
        do 
            echo '$i'
        done
]'

but it displays only one last element in the array please give me suggestions I'm new to the shell script

Barmar :

Use multiple echo statements.

echo 'const routes = ['
for i in "${fnames[@]}"
do
    echo "$i"
done
echo ']'

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=319334&siteId=1