echo
文字處理
用法
echo [text]原樣印出參數並換行;-e 和反斜線的處理在不同 shell 裡不一樣,要穩妥就用 printf。
常用選項
| 選項 | 含義 |
|---|---|
| -n | Leave off the trailing newline |
| -e | Read backslash escapes such as \n. Not in every shell |
| -E | Do not read escapes, which is the usual default |
範例
echo -n doneLeaves the cursor on the same line.
echo "$PATH"Prints a variable; the quotes keep spaces intact.
echo *The shell expands this to the file names, not echo.
它們本來就是用管線串起來用的。串三條往往比讓一條命令做完所有事更短。
怎麼看
- 方括號 [ ] 表示這部分可以不寫。
- 省略號 … 表示可以寫多個。
- 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。
常見問題
Q. echo 是做什麼的?
原樣印出參數並換行;-e 和反斜線的處理在不同 shell 裡不一樣,要穩妥就用 printf。
Q. 怎麼寫?
echo [text] —— 方括號表示可以省略的部分。
Q. 值得記的選項有幾個?
這裡列了 3 個,完整列表在 man echo。這條命令屬於文字處理。
相關命令
man 手冊: man echo