『[改訂第3版]シェルスクリプト基本リファレンス ──#!/bin/shで、ここまでできる』[1]はFreeBSD, Solaris, BusyBoxのshとbashでの各種機能の対応状況を説明しているけれど、ところでPOSIX的にはどうなんだっけというのが気になったので調べてみた。
[1]でFreeBSD, Solaris, BusyBoxのshでサポート状況が食い違う機能について、POSIXに含まれるものを☑︎、POSIXで陽にunspecifiedとされているものを*、POSIXに含まれないものを☐とし、可能であればそれぞれPOSIX、bashまたは該当シェルのマニュアルへのリンクを掲げた。
構文
☑︎ ! cmd1 | cmd2
!
でパイプライン全体の結果を否定できるかどうか。
☑︎ case arg in (pat) ...;; esac
case
のパターンの前に(
を書けるかどうか。
☐ case
の ;&
bashやFreeBSDのshではcase
内で;;
の代わりに;&
とすることでfallthroughできる。
If the selected list is terminated by the control operator `;&' instead of `;;', execution continues with the next list, continuing until a list terminated with `;;' or the end of the case command.
SH(1) FreeBSD General Commands Manual
Using ‘;&’ in place of ‘;;’ causes execution to continue with the command-list associated with the next clause, if any.
Conditional Constructs (Bash Reference Manual)
* [[
〜 ]]
[[
〜 ]]
形式の条件式。
The following words may be recognized as reserved words on some implementations (when none of the characters are quoted), causing unspecified results:
Bash Conditional Expressions (Bash Reference Manual)
☐ &>
Redirections (Bash Reference Manual)
コマンド
☐ .
での引数指定
.
に追加の引数を指定することで、読まれる側のファイルの位置パラメータを設定できるかどうか。
dot - execute commands in the current environment
Bourne Shell Builtins (Bash Reference Manual)
☐ source
Bash Builtins (Bash Reference Manual)
☑︎ cd -P
cd - change the working directory
export
☑︎ export var=val
, export -p
export - set the export attribute for variables
☐ -n
Bourne Shell Builtins (Bash Reference Manual)
read
☑︎ -r
read - read from standard input into shell variables
☐ -p
, -t
, -n
, -s
Bash Builtins (Bash Reference Manual)
☑︎ readonly var=val
, readonly -p
readonly - set the readonly attribute for variables
☑︎ .
されたファイル内での return
return - return from a function or dot script
set
☑︎ -h
, -o
, -C
set - set or unset options and positional parameters
☐ -k
, -p
, -t
, -P
The Set Builtin (Bash Reference Manual)
☑︎ umask -S
, chmod
形式でのumask指定
umask - get or set the file mode creation mask
☑︎ unset -v
, unset -f
unset - unset values and attributes of variables and functions
☐ echo -n
, echo -e
echo - write arguments to standard output
Bash Builtins (Bash Reference Manual)
test
☑︎ -e
, -S
☐ -O
, -G
, -nt
, -ot
, -ef
, ==
, <
, >
Bourne Shell Builtins (Bash Reference Manual)
☑︎ command
command - execute a simple command
* builtin
, let
, local
, bind
, history
, suspend
If the command name matches the name of a utility listed in the following table, the results are unspecified.
☑︎ alias
alias - define or display aliases
☑︎ fc
fc - process the command history list
☑︎ unalias
unalias - remove alias definitions
パラメータ
☑︎ ${10}
etc.
When a positional parameter with more than one digit is specified, the application shall enclose the digits in braces (see Parameter Expansion).
☐ $_
Bash Variables (Bash Reference Manual)
☑︎ ${#var}
☑︎ ${var#pat}
, ${var##pat}
☑︎ ${var%pat}
, ${var%%pat}
☐ ${var:offset}
, ${var:offset:len}
Shell Parameter Expansion (Bash Reference Manual)
☐ ${var/pat/sub}
, ${var//pat/sub}
Shell Parameter Expansion (Bash Reference Manual)
置換・展開
☑︎ $(
〜 )
☑︎ $((
〜 ))
☑︎ ~
参考文献
- [1] 『[改訂第3版]シェルスクリプト基本リファレンス ──#!/bin/shで、ここまでできる』(山森丈範、技術評論社、2017)
- [2] POSIX.1-2017
- [3] Bash Reference Manual
- [4] SH(1) FreeBSD General Commands Manual