怎么在shell中對長命令進(jìn)行換行處理?很多新手對此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
前言
考察下面的腳本:
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
這里在調(diào)用 emcc 進(jìn)行 WebAssembly 編譯時(shí),組織了很多參數(shù)。整個(gè)命令都在一行之中,不是很好閱讀和維護(hù)。
換行
可通過加 \ 的方式來進(jìn)行換行拆分。
改造后看起來像這樣,一個(gè)參數(shù)占一行:
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) 換行后,整體閱讀體驗(yàn)好了很多。進(jìn)一步,我們想要為每個(gè)參數(shù)添加注釋,發(fā)現(xiàn)不能簡單地這樣來:
emcc -o ./dist/test.html\ # 目標(biāo)文件 --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
這樣會導(dǎo)致整個(gè) shell 腳本解析失敗。
實(shí)測發(fā)現(xiàn),也不能這樣:
emcc -o\ # 目標(biā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
同樣會導(dǎo)致解析失敗。
說到底,通過 \ 拆分的命令,只是呈現(xiàn)上變成了多行,其中插入的注釋是會破壞掉語義的。
但也不是沒辦法添加注釋了,幾經(jīng)周轉(zhuǎn)發(fā)現(xiàn)如下寫法是可行的:
emcc -o ./dist/test.html `# 目標(biāo)文件` \ --shell-file ./tmp.html `# 模板文件` \ --source-map-base dist `# source map 根路徑` \ -O3 `# 優(yōu)化級別` \ -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) 來包裹我們的注釋,就不會破壞掉腳本的語義了,能夠正確解析執(zhí)行。
進(jìn)一步,解決了注釋的問題,如果我們不想要某一行,同時(shí)又不想刪除,可以像下面這樣來注釋:
emcc -o ./dist/test.html `# 目標(biāo)文件` \ --shell-file ./tmp.html `# 模板文件` \ --source-map-base dist `# source map 根路徑` \ -O3 `# 優(yōu)化級別` \ -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
看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進(jìn)一步的了解或閱讀更多相關(guān)文章,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,的支持。
文章題目:怎么在shell中對長命令進(jìn)行換行處理-創(chuàng)新互聯(lián)
路徑分享:http://jinyejixie.com/article46/dedeeg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動態(tài)網(wǎng)站、電子商務(wù)、建站公司、網(wǎng)站排名、標(biāo)簽優(yōu)化、企業(yè)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容