GNU Bourne Again Shell(bash)
背景
bash5.0が発表されたので早速使ってみました。
メジャーバージョンアップは4.0の2009年2月ぶりとの事で約10年
マイナーバージョンアップも4.4が2016年9月ぶりです。
後方互換性が多少無いようなのですぐに乗り換えることは出来ませんがとりあえず使ってみました。
4.4との違いはバグフィックスと新機能追加
関係ないですがbashのファーストリリースは1989年との事で今年は記念すべき30周年を向かえるんですね。
未だに第一線で大活躍しているのはすごいです。
使ってみる
まずは下記サイトよりソースを入手します。
http://lists.gnu.org/archive/html/bug-bash/2019-01/msg00063.html
Gitでも公開されているのでそちらからでも入手可能です。
tarを入手したら展開します。
$ tar xvf bash-5.0.tar.gz
次にREADME通りに下記を実行しビルドします
$ CC=cc ./configure
$ make
ビルドしたらbashが出来上がるので起動してみます。
ls
ABOUT-NLS arrayfunc.o config-bot.h expr.o list.o pcomplete.h support
AUTHORS assoc.c config-top.h externs.h locale.c pcomplete.o syntax.c
CHANGES assoc.h config.h findcmd.c locale.o pcomplib.c syntax.h
COMPAT assoc.o config.h.in findcmd.h lsignames.h pcomplib.o syntax.o
COPYING bash config.log findcmd.o m4 po test.c
CWRU bashansi.h config.status flags.c mailcheck.c print_cmd.c test.h
ChangeLog bashbug configure flags.h mailcheck.h print_cmd.o test.o
INSTALL bashhist.c configure.ac flags.o mailcheck.o quit.h tests
MANIFEST bashhist.h conftypes.h general.c make_cmd.c redir.c trap.c
Makefile bashhist.o copy_cmd.c general.h make_cmd.h redir.h trap.h
Makefile.in bashintl.h copy_cmd.o general.o make_cmd.o redir.o trap.o
NEWS bashjmp.h cross-build hashcmd.c mksignames shell.c unwind_prot.c
NOTES bashline.c dispose_cmd.c hashcmd.h mksignames.o shell.h unwind_prot.h
POSIX bashline.h dispose_cmd.h hashcmd.o mksyntax shell.o unwind_prot.o
RBASH bashline.o dispose_cmd.o hashlib.c mksyntax.c sig.c variables.c
README bashtypes.h doc hashlib.h nojobs.c sig.h variables.h
Y2K bashversion error.c hashlib.o parse.y sig.o variables.o
aclocal.m4 bracecomp.c error.h include parser-built siglist.c version.c
alias.c bracecomp.o error.o input.c parser.h siglist.h version.h
alias.h braces.c eval.c input.h patchlevel.h signames.h version.o
alias.o braces.o eval.o input.o pathexp.c stamp-h xmalloc.c
array.c buildsignames.o examples jobs.c pathexp.h stringlib.c xmalloc.h
array.h buildversion.o execute_cmd.c jobs.h pathexp.o stringlib.o xmalloc.o
array.o builtins execute_cmd.h jobs.o pathnames.h subst.c y.tab.c
arrayfunc.c builtins.h execute_cmd.o lib pathnames.h.in subst.h y.tab.h
arrayfunc.h command.h expr.c list.c pcomplete.c subst.o y.tab.o
$ ./bash
$ ./bash --version
GNU bash, version 5.0.0(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
5.0が起動しているが確認できました。
メーリングリストを参考に今すぐ使えそうな機能を何点か使ってみました。
※正式なインストール手順では無いのでREADMEをご一読ください!!!
新機能概要
個人的に気になる機能を使ってみました。
内容はメーリングリストのメールの翻訳なので間違っている箇所がある可能性があります。
気づいた方はご指摘願います。
新しく追加された変数
使いどころは分かりませんが二つの変数が追加されている
UNIX時間の秒数とマイクロ秒付きの値が見れる。
$ echo $EPOCHSECONDS
1546999731
$ echo $EPOCHREALTIME
1546999732.481601
historyの範囲指定削除
こちらも何に使えるのかは検討もつきませんが(履歴の整理にはちょっと便利かも)
コマンド履歴を範囲指定で削除できるようです。
$ history -d 10-20
$BASH_ARGV0の追加
$0同様にシェルまたはシェルスクリプトに展開される変数が追加されました。
$ echo $BASH_ARGV0
./bash
config-top.h
ヘッダファイルが追加されています。
このファイルをビルド前に編集することで静的にbashの設定を行う事が出来ます。
// 複数指定のkillが1つ失敗しても後続のプロセスへの処理を継続する
#define CONTINUE_AFTER_KILL_ERROR
// (中略)
/* $PATHのデフォルト */
#ifndef DEFAULT_PATH_VALUE
#define DEFAULT_PATH_VALUE \
"/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:."
#endif
/* If you want to unconditionally set a value for PATH in every restricted
shell, set this. */
/* #define RBASH_STATIC_PATH_VALUE "/rbin:/usr/rbin" */
/* The value for PATH when invoking `command -p'. This is only used when
the Posix.2 confstr () function, or CS_PATH define are not present. */
#ifndef STANDARD_UTILS_PATH
#define STANDARD_UTILS_PATH \
"/bin:/usr/bin:/sbin:/usr/sbin:/etc:/usr/etc"
#endif
// デフォルトのプライマリおよびセカンダリプロンプト
#define PPROMPT "\\s-\\v\\$ "
#define SPROMPT "> "
/* Undefine this if you don't want the ksh-compatible behavior of reprinting
the select menu after a valid choice is made only if REPLY is set to NULL
in the body of the select command. The menu is always reprinted if the
reply to the select query is an empty line. */
#define KSH_COMPATIBLE_SELECT
// デフォルトの対話型シェル起動ファイル
#define DEFAULT_BASHRC "~/.bashrc"
/* 対話式シェル用のシステム全体の.bashrcファイル */
/* #define SYS_BASHRC "/etc/bash.bashrc" */
// .bash_logoutのデフォルト
#define SYS_BASH_LOGOUT "/etc/bash.bash_logout"
// (中略)
// ソースに必要な最大再帰レベル
#define SOURCENEST_MAX 0
// lib/sh/tmpfile.cの代わりにlibc mktemp/mkstempを使用するように定義。
#define USE_MKTEMP
#define USE_MKSTEMP
// OLDPWDの値をディレクトリにするように定義
#define OLDPWD_CHECK_DIRECTORY 1
// 履歴の保存数
/*#define HISTSIZE_DEFAULT "500"*/
// 履歴の展開の有無のデフォルト
#define HISTEXPAND_DEFAULT 1
まとめ
他にもたくさんのアップデートがありました。
全てを見たい方は公式を見に行くか付属のCHANGESをご参照ください。
waitの話だったりnamerefの話だったり詳しく取りあげてくださっている記事があれば教えてください
参考URL
https://lwn.net/Articles/776223/
https://www.osnews.com/story/129062/bash-5-0-released/