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

如何将SQL脚本内容追加到Shell脚本的EOSQL标记前?

实现SQL脚本内容追加到Shell脚本EOSQL标记前的方法

环境说明

  • Windows 11 专业版 x64
  • Docker Desktop 4.12.0(85629)+ WSL

操作步骤(WSL终端下执行)

1. 路径转换

Windows路径D:\github\spring_jwt\vy_notes\database_postgres_part_001_100.sql在WSL中对应路径为:

/mnt/d/github/spring_jwt/vy_notes/database_postgres_part_001_100.sql

2. 切换到目标脚本目录

假设create-databases.sh位于项目根目录,执行:

cd /mnt/d/github/spring_jwt/

3. 执行插入命令

方法一:使用sed命令

该命令会找到以EOSQL开头的行,并在其之前插入SQL脚本的全部内容:

sed -i '/^EOSQL$/e cat /mnt/d/github/spring_jwt/vy_notes/database_postgres_part_001_100.sql' create-databases.sh

注意:如果脚本是只读权限,需先执行chmod +w create-databases.sh添加写入权限。

方法二:使用awk命令

如果sed命令执行有问题,可尝试awk命令,先将内容输出到临时文件再替换原脚本:

awk '/^EOSQL$/ {system("cat /mnt/d/github/spring_jwt/vy_notes/database_postgres_part_001_100.sql")} 1' create-databases.sh > temp.sh && mv temp.sh create-databases.sh

4. 验证结果

打开create-databases.sh,检查create_database函数中的EOSQL标记前是否已成功追加SQL脚本内容。

手动操作备选方案

如果不想用命令行,可直接通过VS Code等编辑器操作:

  • 同时打开create-databases.sh和database_postgres_part_001_100.sql两个文件
  • 在create-databases.sh中找到EOSQL标记行
  • 复制database_postgres_part_001_100.sql的全部内容,粘贴到EOSQL行之前

内容的提问来源于stack exchange,提问作者Đỗ Như Vỹ

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 11:10:34