Skip to content

Instantly share code, notes, and snippets.

@i03nomura1y
Last active December 15, 2015 11:19
Show Gist options
  • Save i03nomura1y/5252131 to your computer and use it in GitHub Desktop.
Save i03nomura1y/5252131 to your computer and use it in GitHub Desktop.
sh script: 連番を echo する。
#!/bin/sh
# 2013/03/27
# 連番を echo する。
# $ ./iota.sh 10 => 000 .. 010
# $ ./iota.sh 3 5 => 003 .. 005
# $ ./iota.sh 3 5 "%d" => 3 .. 5
# 追記:
# $ seq -w 3 10
# $ seq -f "%03g" 3 5
# $ printf "%03d\n" `seq 3 5`
# で用は足りる
# 引数チェック
CMDNAME=`basename $0`
if [ $# -ne 1 ] && [ $# -ne 2 ] && [ $# -ne 3 ] ; then
echo " Usage: $CMDNAME to" 1>&2
echo " $CMDNAME from to" 1>&2
echo " $CMDNAME from to format" 1>&2
echo " example: $CMDNAME 0 10 \"%02d\"" 1>&2
exit 1;
fi
# カウント開始 / 終了 / 表示フォーマット
from=0;
to=10;
format="%03d";
# 引数をもってくる
if [ $# -eq 1 ] ; then
to=$1
elif [ $# -eq 2 ] ; then
from=$1
to=$2
elif [ $# -eq 3 ] ; then
from=$1
to=$2
format=$3
fi
# 表示
printf "$format\n" `seq $from $to`
# for val in $(seq $from $to); do
# printf "$format\n" $val;
# done;
# おわり
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment