IT pass HikiWiki - [Exp2016]解答例 Diff
- Added parts are displayed like this.
- Deleted parts are displayed
like this.
= Hello World を表示させる任意の回数表示させるスクリプト
== スクリプト例
#!/bin/bash
i=1
while [ $i -le $1 ]
do
echo "Hello World"
i=`expr $i + 1`
done
== 実行例
$ ./exe1.sh 5
Hello World
Hello World
Hello World
Hello World
Hello World
= ファイル名変換
== スクリプト例
#!/bin/bash
for i in {1..95}
do
if [ $i -le 9 ]
then
mv text_0$i.txt 0$i.txt
else
mv text_$i.txt $i.txt
fi
done
== 実行例
$ ls
exe2.sh text_16.txt text_32.txt text_48.txt text_64.txt text_80.txt
text_01.txt text_17.txt text_33.txt text_49.txt text_65.txt text_81.txt
text_02.txt text_18.txt text_34.txt text_50.txt text_66.txt text_82.txt
text_03.txt text_19.txt text_35.txt text_51.txt text_67.txt text_83.txt
text_04.txt text_20.txt text_36.txt text_52.txt text_68.txt text_84.txt
text_05.txt text_21.txt text_37.txt text_53.txt text_69.txt text_85.txt
text_06.txt text_22.txt text_38.txt text_54.txt text_70.txt text_86.txt
text_07.txt text_23.txt text_39.txt text_55.txt text_71.txt text_87.txt
text_08.txt text_24.txt text_40.txt text_56.txt text_72.txt text_88.txt
text_09.txt text_25.txt text_41.txt text_57.txt text_73.txt text_89.txt
text_10.txt text_26.txt text_42.txt text_58.txt text_74.txt text_90.txt
text_11.txt text_27.txt text_43.txt text_59.txt text_75.txt text_91.txt
text_12.txt text_28.txt text_44.txt text_60.txt text_76.txt text_92.txt
text_13.txt text_29.txt text_45.txt text_61.txt text_77.txt text_93.txt
text_14.txt text_30.txt text_46.txt text_62.txt text_78.txt text_94.txt
text_15.txt text_31.txt text_47.txt text_63.txt text_79.txt text_95.txt
$ ./exe2.sh
$ ls
01.txt 11.txt 21.txt 31.txt 41.txt 51.txt 61.txt 71.txt 81.txt 91.txt
02.txt 12.txt 22.txt 32.txt 42.txt 52.txt 62.txt 72.txt 82.txt 92.txt
03.txt 13.txt 23.txt 33.txt 43.txt 53.txt 63.txt 73.txt 83.txt 93.txt
04.txt 14.txt 24.txt 34.txt 44.txt 54.txt 64.txt 74.txt 84.txt 94.txt
05.txt 15.txt 25.txt 35.txt 45.txt 55.txt 65.txt 75.txt 85.txt 95.txt
06.txt 16.txt 26.txt 36.txt 46.txt 56.txt 66.txt 76.txt 86.txt exe2.sh
07.txt 17.txt 27.txt 37.txt 47.txt 57.txt 67.txt 77.txt 87.txt
08.txt 18.txt 28.txt 38.txt 48.txt 58.txt 68.txt 78.txt 88.txt
09.txt 19.txt 29.txt 39.txt 49.txt 59.txt 69.txt 79.txt 89.txt
10.txt 20.txt 30.txt 40.txt 50.txt 60.txt 70.txt 80.txt 90.txt
= フィボナッチ数列
== スクリプト例
#!/bin/bash
x=1
y=1
m=11
n=1
echo $x
while [ $n -lt $m ]
do
echo $x
x=`expr $x + $y`
y=`expr $x - $y`
n=`expr $n + 1`
done
== 実行例
$ ./exe3.sh
1
1
2
3
5
8
13
21
34
55
89
== スクリプト例
#!/bin/bash
i=1
while [ $i -le $1 ]
do
echo "Hello World"
i=`expr $i + 1`
done
== 実行例
$ ./exe1.sh 5
Hello World
Hello World
Hello World
Hello World
Hello World
= ファイル名変換
== スクリプト例
#!/bin/bash
for i in {1..95}
do
if [ $i -le 9 ]
then
mv text_0$i.txt 0$i.txt
else
mv text_$i.txt $i.txt
fi
done
== 実行例
$ ls
exe2.sh text_16.txt text_32.txt text_48.txt text_64.txt text_80.txt
text_01.txt text_17.txt text_33.txt text_49.txt text_65.txt text_81.txt
text_02.txt text_18.txt text_34.txt text_50.txt text_66.txt text_82.txt
text_03.txt text_19.txt text_35.txt text_51.txt text_67.txt text_83.txt
text_04.txt text_20.txt text_36.txt text_52.txt text_68.txt text_84.txt
text_05.txt text_21.txt text_37.txt text_53.txt text_69.txt text_85.txt
text_06.txt text_22.txt text_38.txt text_54.txt text_70.txt text_86.txt
text_07.txt text_23.txt text_39.txt text_55.txt text_71.txt text_87.txt
text_08.txt text_24.txt text_40.txt text_56.txt text_72.txt text_88.txt
text_09.txt text_25.txt text_41.txt text_57.txt text_73.txt text_89.txt
text_10.txt text_26.txt text_42.txt text_58.txt text_74.txt text_90.txt
text_11.txt text_27.txt text_43.txt text_59.txt text_75.txt text_91.txt
text_12.txt text_28.txt text_44.txt text_60.txt text_76.txt text_92.txt
text_13.txt text_29.txt text_45.txt text_61.txt text_77.txt text_93.txt
text_14.txt text_30.txt text_46.txt text_62.txt text_78.txt text_94.txt
text_15.txt text_31.txt text_47.txt text_63.txt text_79.txt text_95.txt
$ ./exe2.sh
$ ls
01.txt 11.txt 21.txt 31.txt 41.txt 51.txt 61.txt 71.txt 81.txt 91.txt
02.txt 12.txt 22.txt 32.txt 42.txt 52.txt 62.txt 72.txt 82.txt 92.txt
03.txt 13.txt 23.txt 33.txt 43.txt 53.txt 63.txt 73.txt 83.txt 93.txt
04.txt 14.txt 24.txt 34.txt 44.txt 54.txt 64.txt 74.txt 84.txt 94.txt
05.txt 15.txt 25.txt 35.txt 45.txt 55.txt 65.txt 75.txt 85.txt 95.txt
06.txt 16.txt 26.txt 36.txt 46.txt 56.txt 66.txt 76.txt 86.txt exe2.sh
07.txt 17.txt 27.txt 37.txt 47.txt 57.txt 67.txt 77.txt 87.txt
08.txt 18.txt 28.txt 38.txt 48.txt 58.txt 68.txt 78.txt 88.txt
09.txt 19.txt 29.txt 39.txt 49.txt 59.txt 69.txt 79.txt 89.txt
10.txt 20.txt 30.txt 40.txt 50.txt 60.txt 70.txt 80.txt 90.txt
= フィボナッチ数列
== スクリプト例
#!/bin/bash
x=1
y=1
m=11
n=1
echo $x
while [ $n -lt $m ]
do
echo $x
x=`expr $x + $y`
y=`expr $x - $y`
n=`expr $n + 1`
done
== 実行例
$ ./exe3.sh
1
1
2
3
5
8
13
21
34
55
89