【问题标题】:Get Bash MINGW32 doesn't except array length with surrounding Parenthesis获取 Bash MINGW32 不包括带有括号的数组长度
【发布时间】:2019-01-27 17:29:31
【问题描述】:

我对 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.

【问题讨论】:

  • 我有点怀疑。您的错误消息似乎不在括号附近。我想知道问题是否可能与 Windows 与非 Windows 行结尾有关,而您的文件编辑器在您进行更改时偶然修复了该问题? (只是猜测。)
  • 顺便说一句,即使您的分析确实是正确的,那仍然不会给您带来跨平台问题。括号不是必需的;您可以从脚本的两个版本中删除它们。

标签: bash mingw32


【解决方案1】:

"syntax error near unexpected token 'newline'" 很可能表示 DOS 行结束符或数组中的其他无关字符导致问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-13
    • 1970-01-01
    相关资源
    最近更新 更多