zoukankan      html  css  js  c++  java
  • shell书写换行 便于阅读 转载

    转载:https://www.jb51.net/article/165139.htm

    前言

    考察下面的脚本:

    emcc -o ./dist/test.html --shell-file ./tmp.html --source-map-base dist -O3 -g4 --source-map-base dist -s MODULARIZE=1 -s "EXPORT_NAME="Test"" -s USE_SDL=2 -s LEGACY_GL_EMULATION=1 --pre-js ./pre.js --post-js ./post.js --cpuprofiler --memoryprofiler --threadprofilermain.cpp

    换行

    可通过加 的方式来进行换行拆分。

    改造后看起来像这样,一个参数占一行:

    emcc -o ./dist/test.html
     --shell-file ./tmp.html
     --source-map-base dist
     -O3
     -g4
     --source-map-base dist
     -s MODULARIZE=1
     -s "EXPORT_NAME="Test""
     -s USE_SDL=2
     -s LEGACY_GL_EMULATION=1
     --pre-js ./pre.js
     --post-js ./post.js
     --cpuprofiler
     --memoryprofiler
     --threadprofiler
     main.cpp

    注释

    通过 (backslash) 换行后,整体阅读体验好了很多。进一步,我们想要为每个参数添加注释,发现不能简单地这样来

    emcc -o ./dist/test.html # 目标文件
     --shell-file ./tmp.html # 模板文件
     --source-map-base dist
     -O3
     -g4
     --source-map-base dist
     -s MODULARIZE=1
     -s "EXPORT_NAME="Test""
     -s USE_SDL=2
     -s LEGACY_GL_EMULATION=1
     --pre-js ./pre.js
     --post-js ./post.js
     --cpuprofiler
     --memoryprofiler
     --threadprofiler
     main.cpp

    这样会导致整个 shell 脚本解析失败。

    实测发现,也不能这样:

    emcc -o
     # 目标文件
     ./dist/test.html 
      # 模板文件
     --shell-file ./tmp.html
     --source-map-base dist
     -O3
     -g4
     --source-map-base dist
     -s MODULARIZE=1
     -s "EXPORT_NAME="Test""
     -s USE_SDL=2
     -s LEGACY_GL_EMULATION=1
     --pre-js ./pre.js
     --post-js ./post.js
     --cpuprofiler
     --memoryprofiler
     --threadprofiler
     main.cpp
     

    同样会导致解析失败。

    说到底,通过 拆分的命令,只是呈现上变成了多行,其中插入的注释是会破坏掉语义的。

    但也不是没办法添加注释了,几经周转发现如下写法是可行的:

    emcc -o ./dist/test.html `# 目标文件` 
     --shell-file ./tmp.html `# 模板文件` 
     --source-map-base dist `# source map 根路径` 
     -O3 `# 优化级别` 
     -g4 `# 生成 debug 信息` 
     --source-map-base dist
     `# -s MODULARIZE=1\`
     -s "EXPORT_NAME="Test""
     -s USE_SDL=2
     -s LEGACY_GL_EMULATION=1
     --pre-js ./pre.js
     --post-js ./post.js
     --cpuprofiler
     --memoryprofiler
     --threadprofiler
     main.cpp

    即通过 `(backtick) 来包裹我们的注释,就不会破坏掉脚本的语义了,能够正确解析执行。

    进一步,解决了注释的问题,如果我们不想要某一行,同时又不想删除,可以像下面这样来注释:

    emcc -o ./dist/test.html `# 目标文件` 
     --shell-file ./tmp.html `# 模板文件` 
     --source-map-base dist `# source map 根路径` 
     -O3 `# 优化级别` 
     -g4 `# 生成 debug 信息` 
     --source-map-base dist
     -s MODULARIZE=1
     -s "EXPORT_NAME="Test""
     -s USE_SDL=2
     -s LEGACY_GL_EMULATION=1
     `# --pre-js ./pre.js`
     --post-js ./post.js
     --cpuprofiler
     `# --threadprofiler`
     --memoryprofiler
     main.cpp
  • 相关阅读:
    2019-2020-1 20175202 20175204 20175216 《信息安全系统设计基础》实验三 并发程序
    2019-2020-1 20175202 20175204 20175216 《信息安全系统设计基础》实验二 固件程序设计
    2019-2020-1 20175202 20175204 20175216 《信息安全系统设计基础》实验一 开发环境的熟悉
    2019-2020-1 20175202 《信息安全系统设计基础》第二周学习总结
    2018-2019-2 20175202实验五《网络编程与安全》实验报告
    ucosii
    ls实现及对ls的改进
    mystate实现
    2019—2020 20175203 20175206 实验五 通讯协议设计补交
    20175203-20175206 实验四 《外设驱动程序设计》
  • 原文地址:https://www.cnblogs.com/shixun/p/13872424.html
Copyright © 2011-2022 走看看