Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
OrganizationEventAdvent CalendarQiitadon (β)
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

POSIX sh互換性メモ

『[改訂第3版]シェルスクリプト基本リファレンス ──#!/bin/shで、ここまでできる』[1]はFreeBSD, Solaris, BusyBoxのshとbashでの各種機能の対応状況を説明しているけれど、ところでPOSIX的にはどうなんだっけというのが気になったので調べてみた。

[1]でFreeBSD, Solaris, BusyBoxのshでサポート状況が食い違う機能について、POSIXに含まれるものを☑︎、POSIXで陽にunspecifiedとされているものを*、POSIXに含まれないものを☐とし、可能であればそれぞれPOSIX、bashまたは該当シェルのマニュアルへのリンクを掲げた。


☑︎ ! cmd1 | cmd2


2.9.2 Pipelines

☑︎ case arg in (pat) ...;; esac


Case Conditional Construct



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:

2.4 Reserved Words

Bash Conditional Expressions (Bash Reference Manual)


Redirections (Bash Reference Manual)


. での引数指定

. に追加の引数を指定することで、読まれる側のファイルの位置パラメータを設定できるかどうか。

dot - execute commands in the current environment

Bourne Shell Builtins (Bash Reference Manual)


Bash Builtins (Bash Reference Manual)

☑︎ cd -P

cd - change the working directory


☑︎ export var=val, export -p

export - set the export attribute for variables


Bourne Shell Builtins (Bash Reference Manual)


☑︎ -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


☑︎ -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)


☑︎ -e, -S

test - evaluate expression

-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.

Command Search and Execution

☑︎ 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).

2.5.1 Positional Parameters


Bash Variables (Bash Reference Manual)

☑︎ ${#var}

2.6.2 Parameter Expansion

☑︎ ${var#pat}, ${var##pat}

2.6.2 Parameter Expansion

☑︎ ${var%pat}, ${var%%pat}

2.6.2 Parameter Expansion

${var:offset}, ${var:offset:len}

Shell Parameter Expansion (Bash Reference Manual)

${var/pat/sub}, ${var//pat/sub}

Shell Parameter Expansion (Bash Reference Manual)


☑︎ $()

2.6.3 Command Substitution

☑︎ $(())

2.6.4 Arithmetic Expansion

☑︎ ~

2.6.1 Tilde Expansion


Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Help us understand the problem. What is going on with this article?