Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
syntax: fix a bug that "eval() { :; }" is not parsed as a function de…
…finition
- Loading branch information
1 parent
c70a3b4
commit b429095
Showing
4 changed files
with
54 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 はできない。当たり前といえば当たり前の結果である。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters