Last active
March 13, 2017 14:02
-
-
Save ponsuke0531/056f22de283a01328dad8b2a6c248348 to your computer and use it in GitHub Desktop.
bashのshellで2次元配列を使ってHTMLのテーブルを作る方法 ref: http://qiita.com/ponsuke0531/items/86df8752d8a4c4e9ca92
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in "${dataArray[@]}"; do | |
data=${i[@]} | |
<省略> | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dataArray=( | |
('くま' 'もり' 'peachpuff') | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ bash htmlMaker.sh | |
htmlMaker.sh: line 4: syntax error near unexpected token `(' | |
htmlMaker.sh: line 4: ` ('くま' 'もり' 'peachpuff')' | |
htmlMaker.sh: line 9: syntax error near unexpected token `)' | |
htmlMaker.sh: line 9: `)' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in $dataArray; do | |
data=$i | |
animal=$data[0] | |
place=$data[1] | |
color=$data[2] | |
<省略> | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<table bordercolor="black"> | |
<tr> | |
<th>動物</th> | |
<th>居場所</th> | |
</tr> | |
<tr> | |
<td bgcolor="くま[2]">くま[0]</td> | |
<td bgcolor="くま[2]">くま[1]</td> | |
</tr> | |
<tr> | |
<td bgcolor="もり[2]">もり[0]</td> | |
<td bgcolor="もり[2]">もり[1]</td> | |
</tr> | |
<tr> | |
<td bgcolor="peachpuff[2]">peachpuff[0]</td> | |
<td bgcolor="peachpuff[2]">peachpuff[1]</td> | |
</tr> | |
</table> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in ${dataArray[@]}; do | |
data=$i | |
animal=${data[0]} | |
place=${data[1]} | |
color=${data[2]} | |
<省略> | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<table bordercolor="black"> | |
<tr> | |
<th>動物</th> | |
<th>居場所</th> | |
</tr> | |
<tr> | |
<td bgcolor="">くま</td> | |
<td bgcolor=""></td> | |
</tr> | |
<tr> | |
<td bgcolor="">もり</td> | |
<td bgcolor=""></td> | |
</tr> | |
<tr> | |
<td bgcolor="">peachpuff</td> | |
<td bgcolor=""></td> | |
</tr> | |
<tr> | |
<td bgcolor="">ねこ</td> | |
<省略> | |
<td bgcolor="">lightblue</td> | |
<td bgcolor=""></td> | |
</tr> | |
</table> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in "${dataArray[@]}"; do | |
data=$i | |
<省略> | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<table bordercolor="black"> | |
<tr> | |
<th>動物</th> | |
<th>居場所</th> | |
</tr> | |
<tr> | |
<td bgcolor="">くま もり peachpuff</td> | |
<td bgcolor=""></td> | |
</tr> | |
<tr> | |
<td bgcolor="">ねこ まち lightpink</td> | |
<td bgcolor=""></td> | |
</tr> | |
<tr> | |
<td bgcolor="">さる 上野動物園 burlywood</td> | |
<td bgcolor=""></td> | |
</tr> | |
<tr> | |
<td bgcolor="">りす 鎌倉 khaki</td> | |
<td bgcolor=""></td> | |
</tr> | |
<tr> | |
<td bgcolor="">魚 海 lightblue</td> | |
<td bgcolor=""></td> | |
</tr> | |
</table> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
dataArray=( | |
'くま もり peachpuff' | |
'ねこ まち lightpink' | |
'さる 上野動物園 burlywood' | |
'りす 鎌倉 khaki' | |
'魚 海 lightblue' | |
) | |
fileName='Table.html' | |
echo '<html>' > $fileName | |
echo '<table bordercolor="black">' >> $fileName | |
echo '<tr>' >> $fileName | |
echo '<th>動物</th>' >> $fileName | |
echo '<th>居場所</th>' >> $fileName | |
echo '</tr>' >> $fileName | |
for i in "${dataArray[@]}"; do | |
data=(${i[@]}) | |
animal=${data[0]} | |
place=${data[1]} | |
color=${data[2]} | |
echo '<tr>' >> $fileName | |
echo '<td bgcolor="'$color'">'$animal'</td>' >> $fileName | |
echo '<td bgcolor="'$color'">'$place'</td>' >> $fileName | |
echo '</tr>' >> $fileName | |
done | |
echo '</table>' >> $fileName | |
echo '</html>' >> $fileName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<table bordercolor="black"> | |
<tr> | |
<th>動物</th> | |
<th>居場所</th> | |
</tr> | |
<tr> | |
<td bgcolor="peachpuff">くま</td> | |
<td bgcolor="peachpuff">もり</td> | |
</tr> | |
<tr> | |
<td bgcolor="lightpink">ねこ</td> | |
<td bgcolor="lightpink">まち</td> | |
</tr> | |
<tr> | |
<td bgcolor="burlywood">さる</td> | |
<td bgcolor="burlywood">上野動物園</td> | |
</tr> | |
<tr> | |
<td bgcolor="khaki">りす</td> | |
<td bgcolor="khaki">鎌倉</td> | |
</tr> | |
<tr> | |
<td bgcolor="lightblue">魚</td> | |
<td bgcolor="lightblue">海</td> | |
</tr> | |
</table> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment