When I am running following bash script-
#!/bin/bash
items="b.js
a.js
c.js"
startScript='<script src="'
endScript='"></script>'
for item in $items
do
echo $startScript$item$endScript
done
Output:
<script src="c.js"></script>
<script src="a.js"></script>
<script src="b.js"></script>
I want to run this for loop inside generated html file via a bash script. For loop is not working here.
#!/bin/bash
items="b.js
a.js
c.js"
startScript='<script src="'
endScript='"></script>'
cat << noEcho
<HTML>
<HEAD>
<TITLE> Bash Script </TITLE>
</HEAD>
<BODY>
for item in $items
do
echo $startScript $item $endScript
done
</BODY>
</HTML>
noEcho
files=( b.js a.js c.js ), thenfor item in "${files[@]}"; .../bin/shisn't always bash. Second, how is this not working? Third, I'd preferprintftoecho. Fourth, why bash instead of perl?$()if you want to substitute the output of some code into heredoc body text.$items, so I don't know why you'd expectfor item in $itemsto do anything useful even if you did properly have it inside of a command substitution.