I am trying to iterate over an array of file names and substitute the file name inside an absolute path. The code is,#!/bin/bashjsArray=(moment.js datatable.js jquery.js jquery.tmpl.js dt_jq_ui.js report_app.js)for f in /path/to/res/${jsArray[@]}.js;do  echo $fdoneIt returns,/path/to/res/moment.jsdatatable.jsjquery.jsjquery.tmpl.jsdt_jq_ui.jsreport_app.js.jsWhy does only the first element get prefixed, and only the last element get suffixed? I expected entries like,/path/to/res/moment.js/path/to/res/datatable.js................../path/to/res/report_app.js  
Substitute for loop variable in a string pattern
bash;shell;string
Because you told Bash to:~$ echo /path/to/res/${jsArray[@]}.js/path/to/res/moment.js datatable.js jquery.js jquery.tmpl.js dt_jq_ui.js report_app.js.jsYou are just giving one long string. What you want to do is something like~$ for f in ${jsArray[@]}.js     do echo /path/to/res/$f   done/path/to/res/moment.js/path/to/res/datatable.js/path/to/res/jquery.js/path/to/res/jquery.tmpl.js/path/to/res/dt_jq_ui.js/path/to/res/report_app.js.js