File: D1529.test-keyword-funcdef.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 (21 lines) | stat: -rwxr-xr-x 671 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
#!/bin/bash

keywords=('[[' 'time' '!' 'if' 'while' 'until' 'for' 'select' 'case'
          '{' 'then' 'elif' 'else' 'do' '}' 'done' 'fi' 'esac'
          'coproc' 'function')
builtins=('declare' 'readonly' 'typeset' 'local' 'export' 'alias'
          'eval')

for word in "${keywords[@]}" "${builtins[@]}"; do
  if (eval "$word () { :; }" 2>/dev/null); then
    ok+=("$word")
  else
    ng+=("$word")
  fi
done

echo "Can we define a function using 'NAME() { ... }' form with the NAME being keywords/builtins?"
echo "yes: ${ok[*]}"
echo "no: ${ng[*]}"

# 結論: builtin はできる。keyword はできない。当たり前といえば当たり前の結果である。