Skip to content

Commit 1d2fce4

Browse files
committed
pipe
1 parent ea6b34a commit 1d2fce4

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

usr/libexec/helper-scripts/strings.bsh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@
66
br_add() {
77
local in out
88

9-
if (( $# != 1 )); then
10-
printf '%s\n' "br_add: requires exactly one argument" >&2
9+
if (( $# > 1 )); then
10+
printf '%s\n' "br_add: too many arguments" >&2
1111
return 1
1212
fi
1313

14-
in="$1"
14+
if (( $# == 1 )); then
15+
in="$1"
16+
else
17+
in="$(cat)"
18+
fi
19+
1520
## Replace each newline with "<br />\n"
1621
out="${in//$'\n'/'<br />'$'\n'}"
17-
1822
printf '%s\n' "$out"
1923
}
2024

@@ -203,7 +207,12 @@ test2"
203207
test2"
204208
actual_result="$(br_add "$input_string")"
205209
if ! [ "$expected_result" = "$actual_result" ]; then
206-
error "br_add failed!"
210+
error "br_add command failed!"
211+
fi
212+
213+
actual_result="$(printf '%s\n' "$input_string" | br_add)"
214+
if ! [ "$expected_result" = "$actual_result" ]; then
215+
error "br_add pipe failed!"
207216
fi
208217
}
209218

0 commit comments

Comments
 (0)