获取Bash MINGW32除了数组长度和括号外

时间:2019-01-27 17:29:31

标签: 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.

1 个答案:

答案 0 :(得分:0)

很有可能"syntax error near unexpected token 'newline'"指示DOS行结束或数组中其他无关字符会引起问题。