时间:2021-05-22
前言
考察下面的脚本:
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 进行 WebAssembly 编译时,组织了很多参数。整个命令都在一行之中,不是很好阅读和维护。
换行
可通过加 \ 的方式来进行换行拆分。
改造后看起来像这样,一个参数占一行:
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总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
linux下执行shell命令有两种方法在当前shell中执行shell命令在当前shell中产生一个subshell,在subshell中执行shell命令1
经常碰到的场景,需要去除字符串中的前后的空格。在Shell中不像其他语言有strip()来处理,不过也是可以使用诸如awk等命令来处理。下面是一个简单示例:[r
shell脚本读取数据有以下几种方式:1.键盘输入,默认2.从文件中读取3.通过管道命令传递echo的功能:\c:不换行\f:进纸\t:跳格\n:换行\表示转义
管道经常用于拼接命令,通过管道可以执行一些复杂的数据处理操作。以下为在shell中使用管道处理数据的的几个实例示例1:生成一个8位的随机密码tr-dcA-Za-
shell可以在不调用第3方命令,表示不同进制数据。这里总结以下表示方法。shell脚本默认数值是由10进制数处理,除非这个数字某种特殊的标记法或前缀开头.才可