gpt4 book ai didi

linux - 为什么这个简单的脚本在内联和脚本中的行为不同?

转载 作者:太空宇宙 更新时间:2023-11-04 03:41:58 25 4
gpt4 key购买 nike

我有一个简单的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com