File: D1519.posix-option.sh

package info (click to toggle)
ble.sh 0.4.0~git20250321.d4c812b-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 12,516 kB
  • sloc: sh: 71,367; awk: 1,316; cpp: 750; ansic: 186; javascript: 43; makefile: 35
file content (79 lines) | stat: -rw-r--r-- 1,927 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash

cat <<EOF
# With "set -o posix", the functions whose name doesn't have the form of C
# identifier cannot be defined.  The following case fails.

set -o posix
function ble/base/workaround-POSIXLY_CORRECT { true; }

# With "set -o posix", functions of non-POSIX name that are defined before
# setting "set -o posix" can be called.  The following case runs.

function ble/base/workaround-POSIXLY_CORRECT { true; }
set -o posix
ble/base/workaround-POSIXLY_CORRECT

EOF


# function ble/base/workaround-POSIXLY_CORRECT { true; }
# set -o posix
# alias type=echo
# LANG=C \type ble/base/workaround-POSIXLY_CORRECT
# echo "$LANG"

# set -e
# false && true && true
# true && true && true
# echo complete

# unset() { echo unset; }
# eval() { echo eval; }
# builtin() { echo builtin; }
# read() { echo read; }

# set -o posix
# unset
# eval
# builtin
# read < /dev/null


# set -o posix にする事で上書きしている関数を無視して本来の物が実行されるビルト
# インを確認する。
function list-posix-safe-builtins {
  local builtins
  builtins=($(printf '%s\n' $(enable) | sort -u))

  local b posix_safe posix_unsafe
  for b in "${builtins[@]}"; do
    #echo "testing $b..."
    (
      eval "$b() { return 108; }"
      if [[ $b == set ]]; then
        builtin set -p posix
      else
        set -o posix
      fi
      "$b" --help < /dev/null &>/dev/null
    )
    if (($? == 108)); then
      posix_unsafe+=("$b")
    else
      posix_safe+=("$b")
    fi
  done

  echo '# For the following builtins, the original builtins are executed even when'
  echo '# they are overrided by functions with "set -o posix" (POSIXLY_CORRECT=y):'
  echo
  echo "${posix_safe[@]}" | ifold -w 80 -s
  echo
  echo '# For the following builtins, the overriding functions are executed even'
  echo '# when "set -o posix"'
  echo
  echo "${posix_unsafe[@]}" | ifold -w 80 -s
  echo
}
list-posix-safe-builtins