我有一个简单的 bash 脚本用于文件列表:
$ cat process.sh
for i in *; do echo $i; done
$
然后我运行:
$ ./process.sh
a
b
c
d
process.sh
$
和
$ . ./process.sh
$
和
$ for i in *; do echo $i; done
$
我已阅读 Why does Bash behave differently when called as sh
?这解释了内联命令使用 sh
而不是 bash
- 在这种情况下通配符是非 POSIX 吗?
- 为什么执行相同的代码时会出现不同的行为?
- 如何使这个示例发挥作用?
- 还有其他需要注意的情况吗?
最佳答案
已解决。原因是 for
别名不正确。感谢您的回复。
关于linux - 为什么这个简单的脚本在内联和脚本中的行为不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29333046/