Heinrich Schuchardt | 1b0c316 | 2024-01-14 14:53:13 +0100 | [diff] [blame] | 1 | .. index:: |
| 2 | single: echo (command) |
| 3 | |
Heinrich Schuchardt | 00a7961 | 2021-01-21 17:33:44 +0100 | [diff] [blame] | 4 | echo command |
| 5 | ============ |
| 6 | |
| 7 | Synopsis |
| 8 | -------- |
| 9 | |
| 10 | :: |
| 11 | |
| 12 | echo [-n] [args ...] |
| 13 | |
| 14 | Description |
| 15 | ----------- |
| 16 | |
| 17 | The echo command prints its arguments to the console separated by spaces. |
| 18 | |
| 19 | -n |
| 20 | Do not print a line feed after the last argument. |
| 21 | |
| 22 | args |
| 23 | Arguments to be printed. The arguments are evaluated before being passed to |
| 24 | the command. |
| 25 | |
| 26 | Examples |
| 27 | -------- |
| 28 | |
| 29 | Strings are parsed before the arguments are passed to the echo command: |
| 30 | |
| 31 | :: |
| 32 | |
| 33 | => echo "a" 'b' c |
| 34 | a b c |
| 35 | => |
| 36 | |
| 37 | Observe how variables included in strings are handled: |
| 38 | |
| 39 | :: |
| 40 | |
| 41 | => setenv var X; echo "a)" ${var} 'b)' '${var}' c) ${var} |
| 42 | a) X b) ${var} c) X |
| 43 | => |
| 44 | |
| 45 | |
| 46 | -n suppresses the line feed: |
| 47 | |
| 48 | :: |
| 49 | |
| 50 | => echo -n 1 2 3; echo a b c |
| 51 | 1 2 3a b c |
| 52 | => echo -n 1 2 3 |
| 53 | 1 2 3=> |
| 54 | |
| 55 | A more complex example: |
| 56 | |
| 57 | :: |
| 58 | |
| 59 | => for i in a b c; do for j in 1 2 3; do echo -n "${i}${j}, "; done; echo; done; |
| 60 | a1, a2, a3, |
| 61 | b1, b2, b3, |
| 62 | c1, c2, c3, |
| 63 | => |
| 64 | |
| 65 | Return value |
| 66 | ------------ |
| 67 | |
| 68 | The return value $? is always set to 0 (true). |