bash - 获取 Bash MINGW32 不包括带有括号的数组长度
问题描述
我对 git(源代码树安装附带)mingw32 bash 有奇怪的行为。
假设我看到了数组的括号:
for ((i=0; i<(${#list_array[@]}); ++i)); do
done
我收到此错误:
./test.sh: line 1595: syntax error near unexpected token `newline'
./test.sh: line 1595: ` done'
但是当我像这样删除周围的括号时:
for ((i=0; i<${#list_array[@]}; ++i)); do
done
一切正常,结果我有跨平台问题
,因为这个脚本在 Linux 上运行,现在我需要它在 Windows 下运行。
我真的知道这件事的根本原因是什么。
这是我在 mingw32 中的 bash 版本:
$ bash -version
GNU bash, version 4.3.46(2)-release (i686-pc-msys)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
解决方案
最有可能"syntax error near unexpected token 'newline'"
表示阵列中的 DOS 行结尾或其他无关字符导致问题。
推荐阅读
- html - 是否可以使用 CSS 展开 HTML 元素?
- python - 使用参考列创建矩阵乘法
- react-native - 如何在本机中制作这张卡?
- sitecore - 单元测试无法在基于 Helix Visual Studio 模板的解决方案上运行
- python - Selenium Python - 如何使用 Selenium 从 Yahoo Finance 的历史数据中单击时间段
- reactjs - 未捕获的类型错误: snap.data() 未定义
- postgresql - json列中的Postgres计数值
- javascript - Bokeh 中的 processEvents 类比
- r - 在 R 中使用 Plotly 重叠气泡图
- python - 设置 debug=False 时未加载 Django 静态图像