Linux伊甸园论坛 » Shell编程 » 语法正确的函数定义失败 (alias 的陷阱)
clark
版主
-(dearvoid@LinuxEden:Forum)-(~/tmp)- [$$=6362 $?=0] ; cat rc-2 foo() { echo This is function foo } -(dearvoid@LinuxEden:Forum)-(~/tmp)- [$$=6362 $?=0] ; source rc-2 -(dearvoid@LinuxEden:Forum)-(~/tmp)- [$$=6362 $?=0] ; foo This is function foo -(dearvoid@LinuxEden:Forum)-(~/tmp)- [$$=6362 $?=0] ; cat rc-1 ls() { echo This is function ls } -(dearvoid@LinuxEden:Forum)-(~/tmp)- [$$=6362 $?=0] ; source rc-1 bash: rc-1: line 1: syntax error near unexpected token `(' bash: rc-1: line 1: `ls()' -(dearvoid@LinuxEden:Forum)-(~/tmp)- [$$=6362 $?=1] ; bye
查看个人网站
查看详细资料
TOP
-(dearvoid@LinuxEden:Forum)-(~/void/bash)- [$$=7463 $?=0] ; cat confusing-aliases-2.sh #!/bin/bash shopt -s expand_aliases alias foo='echo hello world' # # The following definition is the same as this: # # echo hello world() # { # builtin echo 'this is a function' # } # # It will cause syntax error. # foo() { builtin echo 'this is a function' } foo -(dearvoid@LinuxEden:Forum)-(~/void/bash)- [$$=7463 $?=0] ; ./confusing-aliases-2.sh ./confusing-aliases-2.sh: line 17: syntax error near unexpected token `(' ./confusing-aliases-2.sh: line 17: `foo()' -(dearvoid@LinuxEden:Forum)-(~/void/bash)- [$$=7463 $?=2] ; bye
超级版主
初来乍到