代码: 全选
song@ubuntu-song:/tmp$ bash --version
GNU bash, version 3.1.17(1)-release (i486-pc-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
代码: 全选
song@ubuntu-song:/tmp$ cat haha.sh
#!/bin/sh
function printhaha ()
{
echo 'inner function'
}
echo "outter function"
printhaha
song@ubuntu-song:/tmp$ ./haha.sh
./haha.sh: 3: Syntax error: "(" unexpected
代码: 全选
song@ubuntu-song:/tmp$ cat haha_1.sh
#!/bin/sh
function printhaha
{
echo 'inner function'
}
echo "outter function"
printhaha
song@ubuntu-song:/tmp$ ./haha_1.sh
./haha_1.sh: 3: function: not found
inner function
outter function
./haha_1.sh: 10: printhaha: not found
如果不用function关键字定义函数:
代码: 全选
song@ubuntu-song:/tmp$ cat haha_2.sh
#!/bin/sh
printhaha ()
{
echo 'inner function'
}
echo "outter function"
printhaha
song@ubuntu-song:/tmp$ ./haha_2.sh
outter function
inner function