sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

D1519.posix-option.sh (1927B)


      1 #!/bin/bash
      2 
      3 cat <<EOF
      4 # With "set -o posix", the functions whose name doesn't have the form of C
      5 # identifier cannot be defined.  The following case fails.
      6 
      7 set -o posix
      8 function ble/base/workaround-POSIXLY_CORRECT { true; }
      9 
     10 # With "set -o posix", functions of non-POSIX name that are defined before
     11 # setting "set -o posix" can be called.  The following case runs.
     12 
     13 function ble/base/workaround-POSIXLY_CORRECT { true; }
     14 set -o posix
     15 ble/base/workaround-POSIXLY_CORRECT
     16 
     17 EOF
     18 
     19 
     20 # function ble/base/workaround-POSIXLY_CORRECT { true; }
     21 # set -o posix
     22 # alias type=echo
     23 # LANG=C \type ble/base/workaround-POSIXLY_CORRECT
     24 # echo "$LANG"
     25 
     26 # set -e
     27 # false && true && true
     28 # true && true && true
     29 # echo complete
     30 
     31 # unset() { echo unset; }
     32 # eval() { echo eval; }
     33 # builtin() { echo builtin; }
     34 # read() { echo read; }
     35 
     36 # set -o posix
     37 # unset
     38 # eval
     39 # builtin
     40 # read < /dev/null
     41 
     42 
     43 # set -o posix にする事で上書きしている関数を無視して本来の物が実行されるビルト
     44 # インを確認する。
     45 function list-posix-safe-builtins {
     46   local builtins
     47   builtins=($(printf '%s\n' $(enable) | sort -u))
     48 
     49   local b posix_safe posix_unsafe
     50   for b in "${builtins[@]}"; do
     51     #echo "testing $b..."
     52     (
     53       eval "$b() { return 108; }"
     54       if [[ $b == set ]]; then
     55         builtin set -p posix
     56       else
     57         set -o posix
     58       fi
     59       "$b" --help < /dev/null &>/dev/null
     60     )
     61     if (($? == 108)); then
     62       posix_unsafe+=("$b")
     63     else
     64       posix_safe+=("$b")
     65     fi
     66   done
     67 
     68   echo '# For the following builtins, the original builtins are executed even when'
     69   echo '# they are overrided by functions with "set -o posix" (POSIXLY_CORRECT=y):'
     70   echo
     71   echo "${posix_safe[@]}" | ifold -w 80 -s
     72   echo
     73   echo '# For the following builtins, the overriding functions are executed even'
     74   echo '# when "set -o posix"'
     75   echo
     76   echo "${posix_unsafe[@]}" | ifold -w 80 -s
     77   echo
     78 }
     79 list-posix-safe-builtins