ข้ามไปที่เนื้อหาหลัก

บทความ

กำลังแสดงโพสต์จาก มกราคม, 2016

shell script

Function #!/bin/bash #!/bin/bash function test { echo "test $1 $2 $3"; } test a b c   Inner Function $ outerfunc1() { > innerfunc() { echo "Running inner function #1"; } > echo "Running outer function #1" > } $ outerfunc2() { > innerfunc() { echo "Running inner function #2"; } > echo "Running outer function #2" > } $ # At this point, both outerfunc1 and outerfunc2 contain definitions of $ # innerfunc, but since neither has been executed yet, the definitions $ # haven't "happened". $ innerfunc -bash: innerfunc: command not found $ outerfunc1 Running outer function #1 $ # Now that outerfunc1 has executed, it has defined innerfunc: $ innerfunc Running inner function #1 $ outerfunc2 Running outer function #2 $ # Running outerfunc2 has redefined innerfunc: $ innerfunc Running inner function #2 ref : http://stackoverflow.com/questions/8426077/how-to-define-a-function-inside-another-function-in-bash