https://youtu.be/kyEAws5_vnA
アニメ『アトム ザ・ビギニング』
さすが一話目から面白かったです。これがあの鉄腕アトムになるのか、ふむふむ、と視聴していました。
パンチが凄いことになっていますが、もう原子力使っているのでしょうか。
試作であってもバージョンはつけるべきかと思いますが、前回 –versionでバージョンが表示されなかったコマンドについて詳しく見ていこうかと思います。
FALSEのコマンドを上から見ていきます。
takk@deb8:~/tmp$ head list bash TRUE GNU bash, バージョン 4.3.30(1)-release (x86_64-pc-linux-gnu) bunzip2 TRUE bzip2, a block-sorting file compressor. Version 1.0.6, 6-Sept-2010. busybox FALSE bzcat TRUE bzip2, a block-sorting file compressor. Version 1.0.6, 6-Sept-2010. bzcmp FALSE bzdiff FALSE bzegrep FALSE bzexe FALSE bzfgrep FALSE bzgrep FALSE
まずは上のlistの3行目にあるbusybox。本当に–versionが失敗するか確認してみましょう。
takk@deb8:~/tmp$ busybox --version;echo $? --version: applet not found 1
appletと解釈されているようです。
busyboxのように必ず引数が必要なコマンドの場合は、引数なしでバージョンや使い方が表示されるようになっている場合があります。
引数なしで実行してみます。
takk@deb8:~/tmp$ busybox BusyBox v1.22.1 (Debian 1:1.22.0-9+deb8u1) multi-call binary. BusyBox is copyrighted by many authors between 1998-2012. Licensed under GPLv2. See source distribution for detailed copyright notices. Usage: busybox [function [arguments]...] or: busybox --list[-full] or: busybox --install [-s] [DIR] or: function [arguments]... BusyBox is a multi-call binary that combines many common Unix utilities into a single executable. Most people will create a link to busybox for each function they wish to use and BusyBox will act like whatever it was invoked as. Currently defined functions: [, [[, acpid, adjtimex, ar, arp, arping, ash, awk, basename, blockdev, brctl, bunzip2, bzcat, bzip2, cal, cat, chgrp, chmod, chown, chroot, chvt, clear, cmp, cp, cpio, cttyhack, cut, date, dc, dd, deallocvt, depmod, devmem, df, diff, dirname, dmesg, dnsdomainname, dos2unix, du, dumpkmap, dumpleases, echo, egrep, env, expand, expr, false, fgrep, find, fold, free, freeramdisk, fstrim, ftpget, ftpput, getopt, getty, grep, groups, gunzip, gzip, halt, head, hexdump, hostid, hostname, httpd, hwclock, id, ifconfig, init, insmod, ionice, ip, ipcalc, kill, killall, klogd, last, less, ln, loadfont, loadkmap, logger, login, logname, logread, losetup, ls, lsmod, lzcat, lzma, lzop, lzopcat, md5sum, mdev, microcom, mkdir, mkfifo, mknod, mkswap, mktemp, modinfo, modprobe, more, mount, mt, mv, nameif, nc, netstat, nslookup, od, openvt, patch, pidof, ping, ping6, pivot_root, poweroff, printf, ps, pwd, rdate, readlink, realpath, reboot, renice, reset, rev, rm, rmdir, rmmod, route, rpm, rpm2cpio, run-parts, sed, seq, setkeycodes, setsid, sh, sha1sum, sha256sum, sha512sum, sleep, sort, start-stop-daemon, stat, strings, stty, swapoff, swapon, switch_root, sync, sysctl, syslogd, tac, tail, tar, taskset, tee, telnet, test, tftp, time, timeout, top, touch, tr, traceroute, traceroute6, true, tty, udhcpc, udhcpd, umount, uname, uncompress, unexpand, uniq, unix2dos, unlzma, unlzop, unxz, unzip, uptime, usleep, uudecode, uuencode, vconfig, vi, watch, watchdog, wc, wget, which, who, whoami, xargs, xz, xzcat, yes, zcat takk@deb8:~/tmp$
あっけなくバージョンが表示されましたね。このようにバージョンが表示される場合は先頭行であることが多い気がします。ですので、headで一行表示して確認しましょう。
takk@deb8:~/tmp$ busybox | head -1 BusyBox v1.22.1 (Debian 1:1.22.0-9+deb8u1) multi-call binary. takk@deb8:~/tmp$
次はlistの5行目のbzcmpです。
いきなり引数なしを実行したいと思います。
takk@deb8:~/tmp$ bzcmp Usage: bzcmp [cmp_options] file [file] takk@deb8:~/tmp$
使用方法は表示されますが、バージョンオプションはなさそうです。念の為manも確認します。
BZDIFF(1) General Commands Manual BZDIFF(1)
名前
bzcmp, bzdiff - bzip2 圧縮されたファイルを比較する
書式
bzcmp [ cmp_options ] file1 [ file2 ]
bzdiff [ diff_options ] file1 [ file2 ]
説明
bzcmp と bzdiff は bzip2 圧縮されたファイルに対し、それぞれ cmp と diff
プログラムを呼び出すために使われる。 指定されたすべてのオプションは cmp
や diff に直接渡される。 ファイルが 1 つしか指定されていない場合、比較
されるファイルは file1 と file1.bz2 を伸長したファイルである。 2 つの
ファイルが指定された場合、必要であれば伸長を行ってから、 cmp や diff に
渡される。 終了状態は cmp や diff のものが採用される。
関連項目
cmp(1), diff(1), bzmore(1), bzless(1), bzgrep(1), bzip2(1)
バグ
cmp や diff プログラムのメッセージは、指定されたファイル名ではなく、 テ
ンポラリのファイル名を参照する。
BZDIFF(1)
(END):
バージョンオプションはなさそうです。manから別のコマンドを呼び出しすることはわかりましたが、bzcmpとbzdiffが同じマニュアルとなっているのは何故でしょう。
シンボリックリンクなのか確認します。
takk@deb8:~/tmp$ ls -l /bin/bzcmp lrwxrwxrwx 1 root root 6 3月 28 2015 /bin/bzcmp -> bzdiff takk@deb8:~/tmp$
やはりシンボリックリンクでした。
では、bzdiffを同じように見ていきます。
takk@deb8:~/tmp$ bzdiff Usage: bzdiff [diff_options] file [file] takk@deb8:~/tmp$
bzcmpと同様、使い方が表示されました。
それにしても、bzcmpはbzdiffのシンボリックリンクですが、実行した時の結果が異なるのは何故でしょうか。
bzdiff本体をfileコマンドで確認します。
takk@deb8:~/tmp$ file /bin/bzdiff /bin/bzdiff: POSIX shell script, ASCII text executable takk@deb8:~/tmp$
なんと、スクリプトでしたね。
takk@deb8:~/tmp$ wc -l !$ wc -l /bin/bzdiff 76 /bin/bzdiff takk@deb8:~/tmp$
行数が少ないので全catします。
takk@deb8:~/tmp$ cat -n !$
1 #!/bin/sh
2 # sh is buggy on RS/6000 AIX 3.2. Replace above line with #!/bin/ksh
3
4 # Bzcmp/diff wrapped for bzip2,
5 # adapted from zdiff by Philippe Troin <phil@fifi.org> for Debian GNU/Linux.
6
7 # Bzcmp and bzdiff are used to invoke the cmp or the diff pro-
8 # gram on compressed files. All options specified are passed
9 # directly to cmp or diff. If only 1 file is specified, then
10 # the files compared are file1 and an uncompressed file1.gz.
11 # If two files are specified, then they are uncompressed (if
12 # necessary) and fed to cmp or diff. The exit status from cmp
13 # or diff is preserved.
14
15 PATH="/usr/bin:/bin:$PATH"; export PATH
16 prog=`echo $0 | sed 's|.*/||'`
17 case "$prog" in
18 *cmp) comp=${CMP-cmp} ;;
19 *) comp=${DIFF-diff} ;;
20 esac
21
22 OPTIONS=
23 FILES=
24 for ARG
25 do
26 case "$ARG" in
27 -*) OPTIONS="$OPTIONS $ARG";;
28 *) if test -f "$ARG"; then
29 FILES="$FILES $ARG"
30 else
31 echo "${prog}: $ARG not found or not a regular file"
32 exit 1
33 fi ;;
34 esac
35 done
36 if test -z "$FILES"; then
37 echo "Usage: $prog [${comp}_options] file [file]"
38 exit 1
39 fi
40 set $FILES
41 if test $# -eq 1; then
42 FILE=`echo "$1" | sed 's/.bz2$//'`
43 bzip2 -cd "$FILE.bz2" | $comp $OPTIONS - "$FILE"
44 STAT="$?"
45
46 elif test $# -eq 2; then
47 case "$1" in
48 *.bz2)
49 case "$2" in
50 *.bz2)
51 F=`echo "$2" | sed 's|.*/||;s|.bz2$||'`
52 tmp=`mktemp "${TMPDIR:-/tmp}"/bzdiff.XXXXXXXXXX` || {
53 echo 'cannot create a temporary file' >&2
54 exit 1
55 }
56 bzip2 -cdfq "$2" > "$tmp"
57 bzip2 -cdfq "$1" | $comp $OPTIONS - "$tmp"
58 STAT="$?"
59 /bin/rm -f "$tmp";;
60
61 *) bzip2 -cdfq "$1" | $comp $OPTIONS - "$2"
62 STAT="$?";;
63 esac;;
64 *) case "$2" in
65 *.bz2)
66 bzip2 -cdfq "$2" | $comp $OPTIONS "$1" -
67 STAT="$?";;
68 *) $comp $OPTIONS "$1" "$2"
69 STAT="$?";;
70 esac;;
71 esac
72 else
73 echo "Usage: $prog [${comp}_options] file [file]"
74 exit 1
75 fi
76 exit "$STAT"
なるほどコマンドにバージョンがないのは、スクリプトを見よう、ということでしょうね。
bzcmpもbzdiffもbzip2のラッパーのようです。



コメント
[…] 「コマンドのバージョン確認(busybox/bzcmp)」の続きです。次のリストのbzdiffまで見ました。 […]