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

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

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のパターンの前に(を書けるかどうか。

Case Conditional Construct

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:

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)

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

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
4
Help us understand the problem. What is going on with this article?