怎麼讓echo不換行

怎麼讓echo 不換行呢?如下方法便可以:

echo -e "zonghzha\c" >> test

echo -e "zonghzha" >> test

cat test發現內容爲:

zonghzhazonghzha

以下內容均參考自:https://www.cnblogs.com/my-ShowTime/p/5420555.html

 

echo -e "this is line1\c"  "excepted:this is also the line1"

---->this is line1

=======爲什麼會這樣呢

man  echo 後發現 在echo -e 後,對“\c” 的解釋是:produce no further output  不產生進一步的輸出   ----》自己理解是在\c 後,這一行後面的內容都不會輸出,直接刪掉了

 

再次測試

echo -e "this is line1 \c  these word will disappear"

---->this is line1

 

完全正確!!!

 

【produce

[prəˈdju:s]       美 [prəˈdu:s]     

vt.& vi.   產生;       生產;       製作;       創作   

vt.   製造;       出示;       引起;       [經濟學]生利   

n.   產品;       產量;       產額;       結果   

網絡 發生;   農產品;  】

 

echo  "test1" test2 "test3"

---->test1 test2 test3

 

echo -e  "this is line1\n"  "Excepted:this is line2"

---->this is line1

---->this is line2

 

man echo:

 

ECHO(1)                          User Commands                         ECHO(1)

NAME        echo - display a line of text

SYNOPSIS        echo [SHORT-OPTION]... [STRING]...        echo LONG-OPTION

DESCRIPTION        Echo the STRING(s) to standard output.

       -n     do not output the trailing newline

       -e     enable interpretation of backslash escapes

       -E     disable interpretation of backslash escapes (default)

       --help display this help and exit

       --version               output version information and exit

       If -e is in effect, the following sequences are recognized:

       \\     backslash

       \a     alert (BEL)

       \b     backspace

       \c     produce no further output

       \e     escape

       \f     form feed

       \n     new line

       \r     carriage return

       \t     horizontal tab

       \v     vertical tab

       \0NNN  byte with octal value NNN (1 to 3 digits)

       \xHH   byte with hexadecimal value HH (1 to 2 digits)

       NOTE: your shell may have its own version of echo, which usually super‐        sedes the version described here.  Please refer to your  shell's  docu‐

 

 

 

【轉】http://www.cnblogs.com/perfy/archive/2012/07/24/2605903.html

 

 

linux的echo命令, 在shell編程中極爲常用, 在終端下打印變量value的時候也是常常用到的, 因此有必要了解下echo的用法
echo命令的功能是在顯示器上顯示一段文字,一般起到一個提示的作用。 該命令的一般格式爲: echo [ -n ] 字符串 其中選項n表示輸出文字後不換行;字符串能加引號,也能不加引號。用echo命令輸出加引號的字符串時,將字符串原樣輸出;用echo命令輸出不加引號的字符串時,將字符串中的各個單詞作爲字符串輸出,各字符串之間用一個空格分割。
功能說明:顯示文字。 語   法:echo [-ne][字符串]或 echo [--help][--version] 補充說明:echo會將輸入的字符串送往標準輸出。輸出的字符串間以空白字符隔開, 並在最後加上換行號。 參   數:-n 不要在最後自動換行 -e 若字符串中出現以下字符,則特別加以處理,而不會將它當成一般 文字輸出:    \a 發出警告聲;    \b 刪除前一個字符;    \c 最後不加上換行符號;    \f 換行但光標仍舊停留在原來的位置;    \n 換行且光標移至行首;    \r 光標移至行首,但不換行;    \t 插入tab;    \v 與\f相同;    \\ 插入\字符;    \nnn 插入nnn(八進制)所代表的ASCII字符; –help 顯示幫助 –version 顯示版本信息

 

 

-----------------------------------------------------------------------------------------------

 

Linux的echo命令, 在shell編程中極爲常用, 在終端下打印變量value的時候也是常常用到。

比如:echo可用作顯示註釋,用於一些批命令中需要註釋給用戶看的地方,比如前一條命令執行會花很長時間,常會用echo顯示一條信息讓用戶知道這個時候比較慢,稍微等待一會。

在Linux中echo命令用來在標準輸出上顯示一段字符,比如: echo "the echo command test!"

這個就會輸出“the echo command test!”這一行文字! 

echo "the echo command test!">a.sh 這個就會在a.sh文件中輸出“the echo command test!”這一行文字! 該命令的一般格式爲: echo [ -n ] 字符串其中選項n表示輸出文字後不換行;字符串能加引號,也能不加引號。用echo命令輸出加引號的字符串時,將字符串原樣輸出;用echo命令輸出不加引號的字符串時,將字符串中的各個單詞作爲字符串輸出,各字符串之間用一個空格分割。

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章