shell腳本echo輸出不換行功能增強(qiáng)實(shí)例
這是第8/101個(gè)腳本
There are as many ways to solve this quirky echo problem as there are pages in this book. One of my favorites is very succinct:
function echon { echo "$*" | awk '{ printf "%s" $0 }' }
You may prefer to avoid the overhead incurred when calling the awk command, however, and if you have a user-level command called printf you can use it instead:
echon() { printf "%s" "$*" }
But what if you don't have printf and you don't want to call awk? Then use the tr command:
echon() { echo "$*" | tr -d '\n' }
This method of simply chopping out the carriage return with tr is a simple and efficient solution that should be quite portable.
這個(gè)腳本很簡(jiǎn)單,就是可以用3種不同的函數(shù)(方法)來(lái)實(shí)現(xiàn),輸出后不換行。
相關(guān)文章
使用shell腳本快速登錄容器的實(shí)現(xiàn)步驟
本文主要介紹了使用shell腳本快速登錄容器的實(shí)現(xiàn)步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08Shell中case...in分支語(yǔ)句的應(yīng)用
shell作為一種腳本編程語(yǔ)言,同樣包含循環(huán)、分支等其他程序控制結(jié)構(gòu),從而輕松完成更加復(fù)雜、強(qiáng)大的功能,本文主要介紹了Shell中case...in分支語(yǔ)句的應(yīng)用,感興趣的可以了解一下2023-08-08分享一個(gè)入門(mén)級(jí)可控多線程shell腳本代碼
這篇文章主要介紹了分享一個(gè)入門(mén)級(jí)可控多線程shell腳本代碼,需要的朋友可以參考下2016-02-02linux定時(shí)備份MySQL數(shù)據(jù)庫(kù)并刪除以前的備份文件(推薦)
這篇文章主要介紹了linux定時(shí)備份MySQL數(shù)據(jù)庫(kù)并刪除以前的備份文件,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-01-01