You need to enable JavaScript to run this app. WSL Ubuntu 20.04下Bash脚本报unexpected end of file语法错误
优惠活动
大模型
产品
解决方案
定价
更多

WSL Ubuntu 20.04下Bash脚本报unexpected end of file语法错误

Shell脚本新增目录切换命令后报语法错误问题排查

基础信息

  • 运行环境:Windows子系统(WSL)搭载的Ubuntu 20.04
  • 脚本开发目标:实现批量文件复制、重命名能力
  • 当前开发进度:仅完成文件复制环节逻辑

现有脚本代码

代码中<sourcepath>、<destinationpath>为占位符,对应实际业务路径:

#!/bin/bash
for file in "<sourcepath>"/*; do echo "$file" && cp "$file" "<destinationpath>"
done
cd "<destinationpath>"

故障表现

  • 未新增cd "<destinationpath>"代码前,脚本可正常执行批量复制流程
  • 新增该行代码后,控制台直接抛出syntax error: unexpected end of file错误
  • 已开展的基础排查:确认脚本内容不存在多余空行等直观异常,已通过hexdump -c命令核查脚本末尾两行的实际字节内容,辅助定位问题

核心诉求

定位本次语法报错的根本诱因

内容的提问来源于stack exchange,提问作者Catomancer

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.11.09 16:06:10