首页 > 解决方案 > 获取 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.

标签: bashmingw32

解决方案


最有可能"syntax error near unexpected token 'newline'"表示阵列中的 DOS 行结尾或其他无关字符导致问题。


推荐阅读