0

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

2
  • you will need 3 echos. One for the 1st line, one for the last line. One inside a for loop in the middle. Commented Mar 14, 2020 at 6:05
  • Thnk you for your response .. I did it Commented Mar 14, 2020 at 6:14

1 Answer 1

1

Use multiple echo statements.

echo 'const routes = ['
for i in "${fnames[@]}"
do
    echo "$i"
done
echo ']'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.