Browse Source

Add core.echos -- a safer version of echo

Alois Mahdal 9 years ago
parent
commit
4e9ad05f4b
2 changed files with 15 additions and 0 deletions
  1. 14
    0
      include/core.sh
  2. 1
    0
      test/data/ffoo_api/functions.oracle

+ 14
- 0
include/core.sh View File

@@ -46,6 +46,20 @@ die() {
46 46
 }
47 47
 
48 48
 
49
+echos() {
50
+    #
51
+    # Safer version of echo able to echo "-n"
52
+    #
53
+    # Traditional echo is broken in that it does not
54
+    # distinguish between string to print and its own switches
55
+    # (-e, -E or -n), leading to unexpected behavior.
56
+    #
57
+    # This echo version circumvents this by using printf.
58
+    #
59
+    printf -- '%s\n' "$@"
60
+}
61
+
62
+
49 63
 usage_is() {
50 64
     #
51 65
     # Echo out usage patterns and (by default) exit 2

+ 1
- 0
test/data/ffoo_api/functions.oracle View File

@@ -12,6 +12,7 @@ core.__echo_vars
12 12
 core.debug
13 13
 core.debug_pipe
14 14
 core.die
15
+core.echos
15 16
 core.think
16 17
 core.usage_is
17 18
 core.warn