You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows环境下IntelliJ运行sh文件报ParentContainsErrorRecordException错误

Windows下IntelliJ运行AWS Shell脚本报错的解决方法

问题详情

在Windows系统的IntelliJ IDEA中运行setup-aws.sh脚本时触发PowerShell解析错误,脚本内容如下:

aws configure set aws_access_key_id "test"
aws configure set aws_secret_access_key "test"
aws configure set default.region eu-west-3


aws --endpoint-url=http://localhost:4566 secretsmanager create-secret --name aws/secret --secret-string '{"my_uname":"username","my_pwd":"password"}'

aws --endpoint-url=http://localhost:4566  s3api create-bucket \
              --bucket bucketname \
              --region eu-west-1 \
              --create-bucket-configuration LocationConstraint=eu-west-1

运行后报错信息:

PS C:\Users\username\IdeaProjects\library> "C:\Program Files\Git\bin\bash.exe" C:\Users\username\IdeaProjects\library\setup-aws.sh
At line:1 char:37                                                                                                           
+ ... es\Git\bin\bash.exe" C:\Users\username\IdeaProjects\library\setup-aws.sh                                                 
+                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                    
Unexpected token 'C:\Users\username\IdeaProjects\library\setup-aws.sh' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException           
    + FullyQualifiedErrorId : UnexpectedToken

解决方法

方法1:修正IntelliJ的运行配置

错误根源是PowerShell无法正确解析带空格路径后的脚本参数,调整IntelliJ的运行配置即可解决:

  • 打开Run > Edit Configurations,找到对应的Shell脚本配置
  • 在Interpreter options输入框中添加参数 -c
  • 确保Script path填写的是完整的脚本路径(如C:\Users\username\IdeaProjects\library\setup-aws.sh)
  • 保存配置后重新运行脚本

方法2:直接用Git Bash执行脚本

绕开PowerShell的解析问题,直接在bash环境中运行:

  • 找到脚本所在的文件夹,右键选择Git Bash Here
  • 在弹出的Git Bash窗口中执行命令:./setup-aws.sh

方法3:检查脚本换行符格式(可选)

Windows下默认的CRLF换行符可能导致bash执行异常,可切换为Unix格式的LF:

  • 在IntelliJ右下角找到换行符标识(如显示CRLF)
  • 点击该标识,选择LF保存脚本

内容的提问来源于stack exchange,提问作者Sercan Noyan Germiyanoğlu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 07:50:25