お使いのブラウザで JavaScript が有効になっていないため、このファイルは開けません。有効にして再読み込みしてください。
シェルスクリプト言語論 第10回 (2020-07-16)
プレゼンテーションを開始
共有
ログイン
ファイル
編集
表示
ヘルプ
ユーザー補助機能
デバッグ
新しい変更を表示
閲覧のみ
スクリーン リーダーのサポートを有効にするには、Ctrl+Alt+Z を押します。キーボード ショートカットの詳細については、Ctrl+スラッシュ を押します。
1
シェ
ル
ス
ク
リ
プ
ト
言
語
論
第
10~12
回
(2020-07-16~30)
https://richlab.org/j/3.52
金
沢
大
学
総
合
メ
ディ
ア
基
盤
セ
ン
ター
大
野
浩
之
ユ
ニ
バー
サ
ル
シェ
ル
プ
ロ
グ
ラ
ミ
ン
グ
研
究
所
松
浦
智
之
こ
の
ス
ラ
イ
ド
の
PDF⇒
https://richlab.org/j/3.72
1
2
Shell
Script
Programming
#10~12
(2020-07-16~30)
https://richlab.org/j/3.52
Information
Media
Center,
Kanazawa
Univ.
Hiroyuki
Ohno,
Ph.D.
Universal
Shell
Programming
Lab.
Tomoyuki
Matsuura
You
can
get
this
slide
from
https://richlab.org/j/3.72
2
3
第
10~12
回
概
要
(
2020-07-16~30
)
●
デ
バッ
グ
と
バー
ジョ
ン
管
理
(バー
ジョ
ン
管
理
は
第
15
回
へ
続
く)
○
到
達
目
標
■
シェ
ル
ス
ク
リ
プ
ト
に
お
け
る
デ
バッ
グ
の
方
法
を
知
る
■
専
用
の
道
具
に
頼
ら
ず
と
も、
基
本
的
な
コ
マ
ン
ド
で
バー
ジョ
ン
管
理
が
で
き
る
こ
と
を
理
解
す
る
○
デ
バッ
グ
方
法
―
20
年
本
5-12
■
set
-vx
オ
プ
ショ
ン
に
よ
る
シェ
ル
変
数
等
の
ぞ
き
見
■
tee
コ
マ
ン
ド
に
よ
る
パ
イ
プ
の
中
を
流
れ
る
デー
タ
の
の
ぞ
き
見
○
バー
ジョ
ン
管
理
方
法
■
基
本
は
cron
+
cp
-pr
で
毎
回
コ
ピー
■
POSIX
準
拠
度
を
下
げ
る
な
ら
rsync
で
ハー
ド
リ
ン
ク
を
活
用
し
た
デー
タ
節
約
型
コ
ピー
■
夜
間
コ
ピー
さ
れ、
複
数
で
き
た
バー
ジョ
ン
の
ファ
イ
ル
を
閲
覧
す
る
テ
ク
ニッ
ク
(→
第
15
回)
●
diff
、
grep
、
等々
3
4
Overview
of
#10~12
(2020-07-16)
●
Debugging
and
Version
Management
(the
latter
is
only
part1)
○
Goal
■
Learn
2
debugging
methods
for
shell
scripts
■
Understand
that
version
management
is
possible
only
with
the
basic
UNIX
commands
○
Debugging
methods
■
Watching
state
(e.g.
value
of
a
variable)
in
every
line
with
“set
-vx”
command
■
Watching
streaming
data
at
some
points
in
pipeline
with
“tee”
command
○
Version
management
method
■
Basically,
back
up
the
whole
program
every
time
with
“cron”
and
“cp
-pr”
■
You
can
also
use
“rsync”
command
to
do
it
if
POSIX
compliant
is
not
so
important.
■
Technique
to
check
difference
among
the
versions
(→
#15)
●
diff,
grep
and
so
forth
4
5
今
日
の
テー
マ
5
6
Today’s
issue
6
7
シェ
ル
ス
ク
リ
プ
ト
に
お
け
る
開
発
マ
ネ
ジ
メ
ン
ト
●
デ
バッ
グ
○
そ
も
そ
も
バ
グ
を
つ
く
ら
せ
な
い
○
IDE
の
な
い
シェ
ル
ス
ク
リ
プ
ト
の
2
つ
の
方
法
○
バ
グ
付
き
コー
ド
「数
字
の
マ
ジッ
ク」
の
デ
バッ
グ
演
習
●
バー
ジョ
ン
管
理
○
基
本
は
コ
ピー
(高
度
ば
ver.
管
理
ツー
ル
に
頼
ら
な
い)
○
履
歴
が
見
た
く
ば
UNIX
コ
マ
ン
ド
7
8
Dev.
Management
for
Shell-programming
●
Debugging
○
Don’t
make
bugs
in
the
first
place
○
Two
debugging
methods
without
IDE
○
An
exercise
by
debugging
“Numerical
Magic
Program”
●
Version
Management
○
Copy
every
snapshot
with
elementary
UNIX
commands
○
Browse
the
history
with
elementary
UNIX
commands
8
9
1
.
シェ
ル
ス
ク
リ
プ
ト
の
デ
バッ
グ
9
10
1
.
Debugging
for
Shell
Script
10
11
1
-0
.
[原
則]
バ
グ
は
取
る
よ
り、
生
み
出
す
な!
11
12
1
-0
.
Don’t
make
bugs
in
the
first
place!
12
13
そ
の
0
.
[基
本]
バ
グ
は
取
る
よ
り、
生
み
出
す
な
●
デ
バッ
グ
は
そ
も
そ
も
「無
駄
な
作
業」
○
時
間
の
無
駄・
労
力
の
無
駄
○
デ
バッ
グ
で
バ
グ
を
潰
す
く
ら
い
な
ら、
は
じ
め
か
ら
バ
グ
ら
せ
る
な
●
ど
う
やっ
て?
○
1
行
書
い
て
は
テ
ス
ト
せ
よ。
○
分
岐
や
ルー
プ
の
無
い
プ
ロ
グ
ラ
ム
な
ら、
容
易
に
で
き
る。
13
14
#
0.
No
bug
is
better
than
debugging
●
We
waste
time
for
debugging
too
much!
○
Be
careful
not
to
make
bugs
●
How?
○
Always
try
to
run
your
code
after
writing
a
new
line.
○
It’s
possible
if
you
write
a
program
with
neither
branch
nor
loop.
14
15
例
―
ifconfig
か
ら
IPv4
ア
ド
レ
ス
を
抽
出
す
る
場
合
●
ま
ず
は、
必
要
な
行
だ
け
に
絞
り
込
む
15
$
/sbin/ifconfig
|
>
grep
'inet[^6]'
inet
addr:
192.168.161.1
Bcast:192.168.161.255
Mask:255.255.255.0
inet
addr:
200.201.202.203
Bcast:200.201.202.207
Mask:255.255.255.248
inet
addr:127.0.0.1
Mask:255.0.0.0
$
必
要
な
行
だ
け
に
絞
り
込
め
て
い
る
か、
こ
こ
で
テ
ス
ト
(確
認)
16
Ex.
--
getting
IPv4
address
from
ifconfig
output
●
At
first,
delete
unnecessary
lines
16
$
/sbin/ifconfig
|
>
grep
'inet[^6]'
inet
addr:
192.168.161.1
Bcast:192.168.161.255
Mask:255.255.255.0
inet
addr:
200.201.202.203
Bcast:200.201.202.207
Mask:255.255.255.248
inet
addr:127.0.0.1
Mask:255.0.0.0
$
“Can
I
succeed
to
delete
them?”
Make
sure
that
right
now!
17
例
―
ifconfig
か
ら
IPv4
ア
ド
レ
ス
を
抽
出
す
る
場
合
●
“inet”
の
直
後
の
数
列
(x.x.x.x)
が
欲
し
い
の
で、
と
り
あ
え
ず
“inet”+1
文
字
(“6”
以
外)
ま
で
を
消
す。
17
$
/sbin/ifconfig
|
>
grep
'inet[^6]'
|
>
sed
's/^.*inet[^6]//'
addr:
192.168.161.1
Bcast:192.168.161.255
Mask:255.255.255.0
addr:
200.201.202.203
Bcast:200.201.202.207
Mask:255.255.255.248
addr:127.0.0.1
Mask:255.0.0.0
$
“inet”+1
文
字
(
“6”
以
外)
ま
で
消
せ
て
い
る
か、
こ
こ
で
テ
ス
ト
(確
認)
18
Ex.
--
getting
IPv4
address
from
ifconfig
output
●
Next,
remove
the
former
string
than
“inet”
(not
“inet6”).
18
$
/sbin/ifconfig
|
>
grep
'inet[^6]'
|
>
sed
's/^.*inet[^6]//'
addr:
192.168.161.1
Bcast:192.168.161.255
Mask:255.255.255.0
addr:
200.201.202.203
Bcast:200.201.202.207
Mask:255.255.255.248
addr:127.0.0.1
Mask:255.0.0.0
$
“Can
I
succeed
to
remove
it?”
Make
sure
that
right
now!
19
例
―
ifconfig
か
ら
IPv4
ア
ド
レ
ス
を
抽
出
す
る
場
合
●
最
初
に
出
て
く
る
数
列
(x.x.x.x)
だ
け、
最
初
の
数
列
よ
り
後
ろ
の
文
字
列
を
削
る。
19
$
/sbin/ifconfig
|
>
grep
'inet[^6]'
|
>
sed
's/^.*inet[^6]//'
|
>
sed
's/\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*$/\1/'
addr:
192.168.161.1
addr:
200.201.202.203
addr:127.0.0.1
$
最
初
の
数
列
よ
り
後
ろ
の
文
字
列
を
削
れ
て
い
る
か、
こ
こ
で
テ
ス
ト
(確
認)
20
Ex.
--
getting
IPv4
address
from
ifconfig
output
●
Keep
only
the
first
IPv4
formatted
string,
and
remove
the
whole
following
string.
20
$
/sbin/ifconfig
|
>
grep
'inet[^6]'
|
>
sed
's/^.*inet[^6]//'
|
>
sed
's/\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*$/\1/'
addr:
192.168.161.1
addr:
200.201.202.203
addr:127.0.0.1
$
“Can
I
succeed
to
keep
only
the
first
part?”
Make
sure
that
right
now!
21
例
―
ifconfig
か
ら
IPv4
ア
ド
レ
ス
を
抽
出
す
る
場
合
●
同
様
に
し
て、
最
初
の
数
列
よ
り
前
の
文
字
列
を
削
る。
(最
初
に
出
て
く
る
数
字
よ
り
手
前
を
削
れ
ば
よ
い)
21
$
/sbin/ifconfig
|
>
grep
'inet[^6]'
|
>
sed
's/^.*inet[^6]//'
|
>
sed
's/\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*$/\1/'
|
>
sed
's/^[^0-9]*//'
192.168.161.1
200.201.202.203
127.0.0.1
$
最
初
に
出
て
く
る
数
字
よ
り
手
前
が
削
れ
て
い
る
か、
こ
こ
で
テ
ス
ト
(確
認)
22
Ex.
--
getting
IPv4
address
from
ifconfig
output
●
Similarly,
Remove
the
former
string
that
the
address.
(It
is
equal
to
remove
non-digit
letter
in
front
of
a
digit)
22
$
/sbin/ifconfig
|
>
grep
'inet[^6]'
|
>
sed
's/^.*inet[^6]//'
|
>
sed
's/\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*$/\1/'
|
>
sed
's/^[^0-9]*//'
192.168.161.1
200.201.202.203
127.0.0.1
$
“Can
I
succeed
to
remove
the
former
string?”
Make
sure
that
right
now!
23
例
―
ifconfig
か
ら
IPv4
ア
ド
レ
ス
を
抽
出
す
る
場
合
●
「
localhost(127.x.x.x)
は
不
要」
と
い
う
要
求
だっ
た
の
で、
そ
の
行
は
削
る。
(こ
れ
で
完
成)
23
$
/sbin/ifconfig
|
>
grep
'inet[^6]'
|
>
sed
's/^.*inet[^6]//'
|
>
sed
's/\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*$/\1/'
|
>
sed
's/^[^0-9]*//'
|
>
grep
-v
'^127\.'
192.168.161.1
200.201.202.203
$
127.0.0.1
が
削
れ
て
い
る
か、
こ
こ
で
テ
ス
ト
(確
認)
24
Ex.
--
getting
IPv4
address
from
ifconfig
output
●
At
the
end,
remove
the
line
which
contain
the
loopback
address
(127.x.x.x).
That’s
all.
24
$
/sbin/ifconfig
|
>
grep
'inet[^6]'
|
>
sed
's/^.*inet[^6]//'
|
>
sed
's/\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*$/\1/'
|
>
sed
's/^[^0-9]*//'
|
>
grep
-v
'^127\.'
192.168.161.1
200.201.202.203
$
“Can
I
succeed
to
remove
the
loopback
address?”
Make
sure
that
right
now!
25
例
―
ifconfig
か
ら
IPv4
ア
ド
レ
ス
を
抽
出
す
る
場
合
●
一
気
に
書
き
終
え
て
か
ら
デ
バッ
グ
し
な
い!
○
ま
と
め
て
や
る
の
で
効
率
が
よ
さ
そ
う
だ
が、
実
は
効
率
が
悪
い。
25
$
/sbin/ifconfig
|
>
grep
'inet[^6]'
|
>
sed
's/^.*inet[^6]//'
|
>
sed
's/\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*$/\1/'
|
>
sed
's/^[^0-9]*//'
|
>
grep
-v
'^127\.'
●
ど
こ
に
バ
グ
が
潜
ん
で
い
る
か、
見
つ
け
る
の
が
手
間
●
バ
グ
が
次
の
バ
グ
を
誘
発
す
る
26
Ex.
--
getting
IPv4
address
from
ifconfig
output
●
Don’t
debug
the
whole
code
at
the
end!
○
Efficiency
will
actually
get
worse!
26
$
/sbin/ifconfig
|
>
grep
'inet[^6]'
|
>
sed
's/^.*inet[^6]//'
|
>
sed
's/\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*$/\1/'
|
>
sed
's/^[^0-9]*//'
|
>
grep
-v
'^127\.'
●
It’s
hard
to
find
where
the
bugs
are
lurking.
●
The
first
bug
tends
to
cause
the
next
one.
27
if,case
や
for,while
に
頼っ
て
い
る
と
そ
う
は
い
か
な
い
●
fi
や
esac,done
ま
で
書
か
な
い
と
動
か
な
い
か
ら。
○
だ
か
ら、
パ
イ
プ
を
積
極
的
に
使
う
べ
き。
27
cat
HOGE_FILE.txt
|
while
read
line;
do
if
grep
'^#';
then
:
elif
grep
'^#';
then
:
fi
done
こ
こ
ま
で
書
か
な
い
と
syntax
error
に
なっ
て
し
ま
う。
28
You
can’t
debug
like
that
if
you
use
“if”,
“while”...
●
Because
“fi”,
“done”
are
required
to
run
it
○
So,
you
should
use
pipeline
“|”
actively
28
cat
HOGE_FILE.txt
|
while
read
line;
do
if
grep
'^#';
then
:
elif
grep
'^#';
then
:
fi
done
It
will
be
regarded
as
errors
unless
these
words
are
written
29
と
は
言
え、
そ
れ
で
も
バ
グ
は
出
る。
●
さっ
き
の
手
段
で
完
全
に
な
く
せ
る
わ
け
で
は
な
い
○
テ
ス
ト
時
に
は
想
定
し
て
い
な
かっ
た
デー
タ
が
来
た
場
合
○
テ
ス
ト
時
の
ミ
ス・
勘
違
い・
忘
れ
●
じゃ
あ
ど
う
す
る?
○
シェ
ル
ス
ク
リ
プ
ト
に
は
デ
バッ
グ
ツー
ル
が
な
い。
○
2
つ
の
手
段
(実
行
ロ
グ
or
コ
マ
ン
ド)
で
デ
バッ
グ
す
る
29
30
However,
we
can’t
eradicate
bugs...
●
The
technique
is
not
perfect,
e.g.
○
What
if
data
we
didn’t
expect
in
the
rehearsal
will
come?
○
What
if
we
mistook/misunderstood
in
the
rehearsal?
●
So
what
can
we
do?
○
There
is
no
debugging
application
for
shell
script
○
But
we
know
two
methods
to
debug
them.
30
31
[デ
バッ
グ
題
材]
答
え
が
必
ず
1089
に
な
る
「数
字
の
マ
シ
゙
ッ
ク」
31
32
[Exercise]
“Numerical
Magic
Programs”
32
33
デ
バッ
グ
の
題
材
―
「数
字
の
マ
ジッ
ク」
と
い
う
数
遊
び
●
次
の
操
作
を
す
る
と
必
ず
1089
に
な
る
ら
し
い
1.
好
き
な
3
桁
の
数
a
(た
だ
し
数
字
は
す
べ
て
違
う
も
の
に
す
る)
を
思
い
浮
か
べ
る。
2.
そ
の
3
桁
の
数
a
の
左
右
を
入
れ
替
え
た
数
b
を
作
る。
3.
a
と
b
の
差
x
を
求
め
る
(
2
桁
に
なっ
た
ら
0
埋
め
し
て
3
桁
に
す
る)
4.
そ
の
3
桁
の
数
x
の
左
右
を
入
れ
替
え
た
数
y
を
作
る。
5.
x
と
y
の
和
を
求
め
る
と
……
、
な
ん
と
必
ず
1089
に!
●
ま
ず
は、
紙
と
鉛
筆
で
確
か
め
て
み
よ。
33
34
A
number
play
“1089”
●
Everyone
surely
get
1089
by
the
following
ops.
1.
Imagine
a
number
“
a
”
that
consists
of
3-digits
which
nums
are
all
different.
2.
Swap
the
1st
and
3rd
digit
to
“
b
”.
3.
Calculate
the
difference
of
a
and
b
to
“
x
”.
(Pad
zero
if
x
would
be
a
2-digit)
4.
Swap
the
1st
and
3rd
digit
of
x
to
“
y
”.
5.
Add
x
and
y
at
last.
The
answer
must
be
1089
!
●
Make
sure
that
right
now
by
yourself!
34
35
1-1
.
実
行
ロ
グ
に
よ
る
デ
バッ
グ
35
36
1-1
.
Debugging
by
“Execution
Log”
36
37
実
行
ロ
グ
に
よ
る
デ
バッ
グ
と
は?
●
sh
コ
マ
ン
ド
の、
-v
、
-x
オ
プ
ショ
ン
を
使
う
方
法
○
現
在
実
行
中
の
行
が
stderr
に
出
力
さ
れ
る。
(
-v
は、
付
近
の
行
も
加
わっ
て
よ
り
詳
細
に
な
る)
○
シェ
ル
変
数
の
中
身
も
出
力
さ
れ
る。
●
具
体
的
な
方
法
○
シェ
ル
ス
ク
リ
プ
ト
の
冒
頭
で
“
#!/bin/sh
-vx
”
と
記
述
(ま
た
は、
途
中
で
“
set
-vx
”
と
記
述)
○
か
つ、
“
exec
2>logfile.$(date
'+%Y%m%d%H%M%S').$$.log
”
な
ど
と
書
け
ば、
以
降
の
ロ
グ
が
ファ
イ
ル
に
出
力
さ
れ
る。
37
38
What
is
“Debugging
by
‘Execution
Log’?”
●
It’s
by
“-v”
and
“-x”
options
on
“sh”
command.
○
They
generate
and
send
“execution
log”
to
stderr.
(
”-v”
makes
the
log
more
verbose
)
○
The
log
also
contains
the
value
which
is
in
shell
variables.
●
How
do
I
use
it?
○
Write
“
#!/bin/sh
-vx
”
in
the
top
line
of
the
shell
script,
or
use
“
set
-vx
”
command
somewhere
in
the
shell
script.
○
And
then
write
“
exec
2>logfile.$(date
'+%Y%m%d%H%M%S').$$.log
”
So,
you
can
get
the
log
as
a
file.
38
39
「数
字
の
マ
ジッ
ク」
(
変
数
版、
実
行
ロ
グ
付)
●
こ
の
プ
ロ
グ
ラ
ム
に
は
バ
グ
が
付
い
て
い
る。
○
ま
ず
は
“magic1.sh”
と
い
う
名
前
で
保
存
し
て、
動
作
確
認
し
て
み
よ。
39
#!/bin/sh
-vx
exec
2>
magic1.$(date
+%Y%m%d%H%M%S).
$$
.log
#
実
行
ロ
グ
を
取
得
#
(こ
の
行
以
降
の
シェ
ル
ス
ク
リ
プ
ト
の
動
作
が
magic1.txt
に
記
録
さ
れ
る)
a
=$(
printf
'%03d'
"
$1
")
b
=$(awk
-v
a=
$a
'BEGIN{print
substr(a,3,1)
substr(a,2,1)
substr(a,1,1)}'
)
x
=$(
printf
'%03d'
$((a-b)))
y
=$(awk
-v
x=
$x
'BEGIN{print
substr(x,3,1)
substr(x,2,1)
substr(x,1,1)}'
)
echo
$((x+y))
40
“Numerical
Magic
1089”
program
(sh-var
version)
●
However,
this
program
has
some
bugs!
○
Save
the
following
script
as
“magic1.sh”
at
first,
and
try
to
run
it.
40
#!/bin/sh
-vx
exec
2>
magic1.$(date
+%Y%m%d%H%M%S).
$$
.log
#
write
down
the
log
as
a
file
#
(the
following
lines
will
be
recorded
into
a
logfile)
a
=$(
printf
'%03d'
"
$1
")
b
=$(awk
-v
a=
$a
'BEGIN{print
substr(a,3,1)
substr(a,2,1)
substr(a,1,1)}'
)
x
=$(
printf
'%03d'
$((a-b)))
y
=$(awk
-v
x=
$x
'BEGIN{print
substr(x,3,1)
substr(x,2,1)
substr(x,1,1)}'
)
echo
$((x+y))
41
「数
字
の
マ
ジッ
ク
」
(変
数
版)
―
動
作
確
認
●
動
作
確
認
し
て
み
る
と
……
●
仕
方
な
い
の
で
実
行
ロ
グ
を
確
認
し
て
み
る
(
⇒
次
頁)
41
$
./magic1.sh
321
1089
$
./magic1.sh
123
$
正
し
い
あ
れ、
答
え
が
出
て
こ
な
い!!
42
“Numerical
Magic
1089”(var
ver.)
-
exec
result
●
The
result
is
...
●
Let’s
check
the
execution
log
(see
the
next
page)
42
$
./magic1.sh
321
1089
$
./magic1.sh
123
$
Correct
No
answer
when
you
give
“123”,
why
not!?
43
「数
字
の
マ
ジッ
ク」
(
変
数
版
)
―
実
行
ロ
グ
43
#!
/bin/sh
-vx
exec
2>
magic1.$(date
+%Y%m%d%H%M%S).$$.log
#
実
行
ロ
グ
を
取
得
+
exec
2>
magic1.20160728180102.12345.log
#
実
行
ロ
グ
を
取
得
#
(こ
の
行
以
降
の
シェ
ル
ス
ク
リ
プ
ト
の
動
作
が
magic1.txt
に
記
録
さ
れ
る)
a=$1
+
a=123
b=$(awk
-v
a=$a
'BEGIN{print
substr(a,3,1)
substr(a,2,1)
substr(a,1,1)}')
awk
-v
a=$a
'BEGIN{print
substr(a,3,1)
substr(a,2,1)
substr(a,1,1)}'
++
awk
-v
a=123
'BEGIN{print
substr(a,3,1)
substr(a,2,1)
substr(a,1,1)}'
+
b=321
x=$(printf
'%03d'
$((a-b)))
printf
'%03d'
$((a-b))
++
printf
%03d
-198
+
x=-198
y=$(awk
-v
x=$x
'BEGIN{print
substr(x,3,1)
substr(x,2,1)
substr(x,1,1)}')
awk
-v
x=$x
'BEGIN{print
substr(x,3,1)
substr(x,2,1)
substr(x,1,1)}'
++
awk
-v
x=-198
'BEGIN{print
substr(x,3,1)
substr(x,2,1)
substr(x,1,1)}'
+
y=91-
echo
$((x+y))
magic1.sh:
line
10:
91-:
syntax
error:
operand
expected
(error
token
is
"-")
44
“Numerical
Magic
1089”(var
ver.)
-
exec
log
44
#!
/bin/sh
-vx
exec
2>
magic1.$(date
+%Y%m%d%H%M%S).$$.log
#
write
down
the
log
as
a
file
+
exec
2>
magic1.20160728180102.12345.log
#
write
down
the
log
as
a
file
#
(the
following
lines
will
be
recorded
into
a
logfile)
a=$1
+
a=123
b=$(awk
-v
a=$a
'BEGIN{print
substr(a,3,1)
substr(a,2,1)
substr(a,1,1)}')
awk
-v
a=$a
'BEGIN{print
substr(a,3,1)
substr(a,2,1)
substr(a,1,1)}'
++
awk
-v
a=123
'BEGIN{print
substr(a,3,1)
substr(a,2,1)
substr(a,1,1)}'
+
b=321
x=$(printf
'%03d'
$((a-b)))
printf
'%03d'
$((a-b))
++
printf
%03d
-198
+
x=-198
y=$(awk
-v
x=$x
'BEGIN{print
substr(x,3,1)
substr(x,2,1)
substr(x,1,1)}')
awk
-v
x=$x
'BEGIN{print
substr(x,3,1)
substr(x,2,1)
substr(x,1,1)}'
++
awk
-v
x=-198
'BEGIN{print
substr(x,3,1)
substr(x,2,1)
substr(x,1,1)}'
+
y=91-
echo
$((x+y))
magic1.sh:
line
10:
91-:
syntax
error:
operand
expected
(error
token
is
"-")
シェ
ル
ス
ク
リ
プ
ト
言
語
論
第
10~12
回
(2020-07-16~30)
https://richlab.org/j/3.52
金
沢
大
学
総
合
メ
ディ
ア
基
盤
セ
ン
ター
大
野
浩
之
ユ
ニ
バー
サ
ル
シェ
ル
プ
ロ
グ
ラ
ミ
ン
グ
研
究
所
松
浦
智
之
こ
の
ス
ラ
イ
ド
の
PDF⇒
https://richlab.org/j/3.72
1
プレゼンテーションの HTML ビュー
スクリーン リーダーのサポートを有効にする