Last active
February 23, 2016 09:36
-
-
Save thatseeyou/34cf5df5e029d7712daa to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# | |
# 편의상 자동으로 child.sh을 만든다. | |
# | |
cat <<'EOF' > child.sh | |
#!/bin/bash | |
echo $(plus_fun $(($1 * $2)) ) | |
EOF | |
chmod +x child.sh | |
plus_fun () { | |
echo $(($1 + 2)); | |
} | |
echo $(plus_fun 5) | |
export -f plus_fun | |
./child.sh 5 2 | |
cat <<'EOF' | |
--- Expected Results -- | |
7 | |
12 | |
EOF |
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
#!/bin/bash | |
# | |
# 함수의 인자에 접근하는 방법 | |
# 다음의 요소가 @, *, "" 의 선택 기준이 된다. | |
# 1. 인자의 공백 유무 | |
# 2. 인자의 구분 여부 | |
# | |
foo() { | |
echo \$@ : $@ | |
echo \$* : $* | |
echo '======== "$@" =======' | |
for v in "$@"; do | |
echo "$v" | |
done | |
echo '======== "$*" =======' | |
for v in "$*"; do | |
echo "$v" | |
done | |
echo '======== $@ =======' | |
for v in $@; do | |
echo "$v" | |
done | |
echo '======== $* =======' | |
for v in $*; do | |
echo "$v" | |
done | |
} | |
foo 1 "2-- --2" 3 | |
cat <<'EOF' | |
--- Expected Results -- | |
$@ : 1 2-- --2 3 | |
$* : 1 2-- --2 3 | |
======== "$@" ======= | |
1 | |
2-- --2 | |
3 | |
======== "$*" ======= | |
1 2-- --2 3 | |
======== $@ ======= | |
1 | |
2-- | |
--2 | |
3 | |
======== $* ======= | |
1 | |
2-- | |
--2 | |
3 | |
EOF |
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
#!/bin/bash | |
foo1 # 여기서는 foo1 함수 정의가 안되어있기 때문에 실행할 수 없다. | |
foo1() { | |
echo "foo1" | |
foo2 # foo1 함수를 실행한 곳이 foo2 아래이므로 실행 가능 | |
} | |
foo2() { | |
echo "foo2" | |
} | |
foo1 # 여기서는 foo1 함수를 실행할 수 있다. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment