奇怪的 Shell 作用域

Yiran at 
工作中很多脚本都是用 Shell 和 Python 完成的,在上周环境中遇到了一个 Bug,导致部分功能失败,最后发现是 Shell 作用域的问题。举例 链接到标题 $ tree . . ├── test.sh └── utils.sh 0 directories, 2 files $ cat utils.sh #!/usr/bin/env bash function echo_test { for i in `seq 2 3`;do echo "utils.sh" $i done } $ cat test.sh #!#/usr/bin/env bash . utils.sh for i in……