Created
May 10, 2012 05:35
-
-
Save tdkn/2651244 to your computer and use it in GitHub Desktop.
kadai
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 | |
# あるディレクトリに保存されている、拡張子.jpgのファイルの拡張子を | |
# 全て.jpegに変えるスクリプトを作成しなさい。 | |
if (($# == 1)); then | |
cd $1 || exit 1 | |
rename .jpg .jpeg *.jpg | |
else | |
echo 'フォルダを1つ指だけ定してください' | |
fi |
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 | |
# 2つの引数が与えられたら、その和を求めて表示し、2つ以上の引数が与えられたときには | |
# 「2つの引数を与えてください」を表示するスクリプトを作成しなさい。 | |
if (($# != 2)); then | |
echo "2つの引数を与えてください" | |
exit 1 | |
else | |
echo "和:$(($1 + $2))" | |
fi | |
exit 0 |
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 | |
# 複数の整数を引数として与えたとき、その合計と平均を表示するスクリプトを作成しなさい。 | |
# ただし、小数点以下は計算しなくてよい。 | |
if (($# <= 0)); then | |
echo '任意の引数を指定してください(複数指定可)' | |
exit 1 | |
fi | |
sum=0 | |
for i in "$@" | |
do | |
sum=$(($sum + $i)) | |
done | |
echo "入力:$*" | |
if (($sum != 0)); then | |
echo "平均値:$(($sum / $#))" | |
else | |
echo '平均値:0' | |
fi |
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 | |
# 現在の時刻が午前7時から10時であれば「おはようございます」、11時から16時であれば「こんにちは」、 | |
# 17時から翌6時であれば「こんばんは」と表示するスクリプトを作成しなさい。 | |
h=`date +%k` | |
if ((7 <= $h && $h <= 10)); then | |
echo 'おはようございます' | |
elif ((11 <= $h && $h <= 16)); then | |
echo 'こんにちは' | |
elif (($h < 24)); then | |
echo 'こんばんわ' | |
fi |
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 | |
# 現在の日付を和暦の月名で表示するスクリプトを作成しなさい。 | |
# ex. | |
# $ koyomi | |
# 2012年 皐月 9日 | |
y=`date +%Y` | |
m=`date +%-m` | |
d=`date +%-d` | |
array=("睦月" "如月" "弥生" "卯月" "皐月" "水無月" "文月" "葉月" "長月" "神無月" "霜月" "師走") | |
echo "$y年 ${array[$m-1]} $d日" |
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 | |
# ファイル名logxxx(xxxには今日の日付を付与、例えばlog20120509)のファイルを作成する。 | |
# 中身はファイル名と同じ1行のテキスト。 | |
date=`date +%Y%m%d` | |
dir=`pwd` | |
echo "create: $dir/log$date" | |
echo "log$date" > log$date |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment