This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision | |||
|
os_cp:redirects_pipes [2025/04/07 21:07] jkonczak added examples |
os_cp:redirects_pipes [2026/03/24 01:04] (current) jkonczak |
||
|---|---|---|---|
| Line 46: | Line 46: | ||
| ==== Printing text ==== | ==== Printing text ==== | ||
| - | ''**echo** //text//'' outputs //text// followed by a newline (unless ''-n'' is specified). \\ | + | ''**echo** //text//'' outputs //text// followed by a newline. \\ |
| - | The ''-e'' switch turns backslash escapes into corresponding characters, e.g., ''\t'' | + | <small> |
| - | becomes a tab and ''\n'' a newline (cf. manual). | + | The ''echo'' command is present in almost any shell of any operating system, |
| + | but there is no consensus on how to interpret switches and how to treat | ||
| + | backslashes in the text. | ||
| + | \\ | ||
| + | In Bash, the ''-n'' switch supresses the newline, and ''-e'' turns backslash | ||
| + | escapes into corresponding characters, e.g., ''\t'' becomes a tab and ''\n'' | ||
| + | a newline (cf. manual). | ||
| + | </small> | ||
| ''**printf** //format// [//arguments//]...'' works roughly the same as the ''printf'' function in C. | ''**printf** //format// [//arguments//]...'' works roughly the same as the ''printf'' function in C. | ||
| <small> | <small> | ||
| - | ''**figlet** [//text//]'' outputs //text// or the standard input by using ascii-art font. | + | Here and there, the course materials make use of the following toy commands: |
| + | \\ | ||
| + | ''**figlet** [//text//]'' outputs //text// or the standard input by using an ascii-art font. | ||
| + | \\ | ||
| ''**cowsay** [//text//]'' makes a cow say the //text// (or the standard input). | ''**cowsay** [//text//]'' makes a cow say the //text// (or the standard input). | ||
| </small> | </small> | ||
| Line 60: | Line 69: | ||
| ++++ Examples | {{page>so:redirects:echo&inline}} ++++ | ++++ Examples | {{page>so:redirects:echo&inline}} ++++ | ||
| - | ~~Exercise.#~~ Try ''echo -e 'foo\n\nbaz' '' \\ and ''echo -e '\n\n one \033[A \033[A two \033[B \033[B \n \033[1;31m red \033[0m' '' \\ <small>[[https://en.wikipedia.org/wiki/ANSI_escape_code|ANSI escape codes]] are well summarized [[https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797|here]]</small> | + | ~~Exercise.#~~ Try the commands ''echo -e 'foo\n\nbaz' '' \\ and ''echo -e '\n\n one \033[A \033[A two \033[B \033[B \n \033[1;31m red \033[0m' '' \\ <small>[[https://en.wikipedia.org/wiki/ANSI_escape_code|ANSI escape codes]] are well summarized [[https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797|here]]</small> |
| ~~Exercise.#~~ Try ''printf "|%4.2f|%3s|%-20s|\n|%4.2f|%3s|%-20s|\n" 3.1428 pi circumference/radius 9.8 g gravity'' | ~~Exercise.#~~ Try ''printf "|%4.2f|%3s|%-20s|\n|%4.2f|%3s|%-20s|\n" 3.1428 pi circumference/radius 9.8 g gravity'' | ||