@@ -66,7 +66,7 @@ function demo_sed() {
6666 local -r input=" Hello, World!"
6767
6868 case " ${ASSUME_GNU} " in
69- yes)
69+ yes | true )
7070 local -r sed_script=' s/World/GNU/g'
7171 # This command will fail if the GNU version of `sed` is not available.
7272 echo " ${input} " | " ${SED} " --regexp-extended " ${sed_script} "
@@ -84,7 +84,7 @@ function demo_awk() {
8484 local -r input=" Hello, World!"
8585
8686 case " ${ASSUME_GNU} " in
87- yes)
87+ yes | true )
8888 # shellcheck disable=SC2016
8989 local -r awk_script=' { print "Hello, GNU!" }'
9090 # This command will fail if the GNU version of `sed` is not available.
@@ -104,7 +104,7 @@ function demo_grep() {
104104 local -r input=" Hello, World!"
105105
106106 case " ${ASSUME_GNU} " in
107- yes)
107+ yes | true )
108108 local -r grep_pattern=" World"
109109 # This command will fail if the GNU version of `grep` is not available.
110110 echo " ${input} " | " ${GREP} " --only-matching " ${grep_pattern} "
@@ -122,7 +122,7 @@ function demo_sort() {
122122 local -r input=" Hello, World!"
123123
124124 case " ${ASSUME_GNU} " in
125- yes)
125+ yes | true )
126126 # This command will fail if the GNU version of `sort` is not available.
127127 echo " ${input} " | " ${SORT} " --ignore-leading-blanks
128128 ;;
@@ -136,7 +136,7 @@ function demo_date() {
136136 echo " DATE Demo:"
137137
138138 case " ${ASSUME_GNU} " in
139- yes)
139+ yes | true )
140140 # This command will fail if the GNU version of `date` is not available.
141141 " ${DATE} " --utc
142142 ;;
@@ -151,7 +151,7 @@ function demo_xargs() {
151151 local -r input=" Hello, World!"
152152
153153 case " ${ASSUME_GNU} " in
154- yes)
154+ yes | true )
155155 # This command will fail if the GNU version of `xargs` is not available.
156156 echo " ${input} " | " ${XARGS} " --no-run-if-empty echo
157157 ;;
@@ -167,7 +167,7 @@ function demo_cut() {
167167 local -r input=" Hello, World!"
168168
169169 case " ${ASSUME_GNU} " in
170- yes)
170+ yes | true )
171171 # This command will fail if the GNU version of `cut` is not available.
172172 echo " ${input} " | " ${CUT} " --characters=3
173173 ;;
@@ -183,7 +183,7 @@ function demo_head() {
183183 local -r input=" Hello, World!"
184184
185185 case " ${ASSUME_GNU} " in
186- yes)
186+ yes | true )
187187 # This command will fail if the GNU version of `head` is not available.
188188 echo " ${input} " | " ${HEAD} " --lines=1
189189 ;;
@@ -199,7 +199,7 @@ function demo_tail() {
199199 local -r input=" Hello, World!"
200200
201201 case " ${ASSUME_GNU} " in
202- yes)
202+ yes | true )
203203 # This command will fail if the GNU version of `tail` is not available.
204204 echo " ${input} " | " ${TAIL} " --lines=1
205205 ;;
@@ -215,7 +215,7 @@ function demo_tr() {
215215 local -r input=" Hello, World!"
216216
217217 case " ${ASSUME_GNU} " in
218- yes)
218+ yes | true )
219219 # This command will fail if the GNU version of `tr` is not available.
220220 echo " ${input} " | " ${TR} " --delete ' '
221221 ;;
@@ -231,7 +231,7 @@ function demo_uniq() {
231231 local -r input=" Hello, World!"
232232
233233 case " ${ASSUME_GNU} " in
234- yes)
234+ yes | true )
235235 # This command will fail if the GNU version of `uniq` is not available.
236236 echo " ${input} " | " ${UNIQ} " --count
237237 ;;
@@ -247,7 +247,7 @@ function demo_wc() {
247247 local -r input=" Hello, World!"
248248
249249 case " ${ASSUME_GNU} " in
250- yes)
250+ yes | true )
251251 # This command will fail if the GNU version of `wc` is not available.
252252 echo " ${input} " | " ${WC} " --words
253253 ;;
@@ -261,25 +261,26 @@ function demo_diff() {
261261 echo " DIFF Demo:"
262262
263263 local -r input1=" Hello, World!"
264- local -r input2=" Hello, Universe!"
265264 local -r file1=" /tmp/file1.txt"
266- local -r file2=" /tmp/file2.txt"
267265
266+ # We just need one file, as the test is just about the command execution,
267+ # not the actual diff output. This spares us the need to handle different
268+ # exit codes (0 for no difference, 1 for difference, 2 for error).
268269 echo " ${input1} " > " ${file1} "
269- echo " ${input2} " > " ${file2} "
270270
271271 case " ${ASSUME_GNU} " in
272- yes)
272+ yes | true )
273273 # This command will fail if the GNU version of `diff` is not available.
274- " ${DIFF} " --brief " ${file1} " " ${file2 } "
274+ " ${DIFF} " --normal " ${file1} " " ${file1 } "
275275 ;;
276276 * )
277- " ${DIFF} " " ${file1} " " ${file2 } "
277+ " ${DIFF} " " ${file1} " " ${file1 } "
278278 ;;
279279 esac
280280}
281281
282282function demo_all() {
283+ echo " Running all demos, assuming GNU available: ${ASSUME_GNU} ."
283284 demo_sed
284285 demo_awk
285286 demo_grep
0 commit comments