return 1
fi
fi
+
+ local strings line
+ if (( $# == 0 )); then
+ unset IFS
+ while read -r line; do
+ strings+=( "$line" )
+ done
+ else
+ strings=( "$@" )
+ fi
+
if ! $new_file; then
if [[ ! -r $file ]]; then
echo "appendu error: cannot read or write $file"
echo "appendu error: cannot read or write $file"
return 1
fi
- fi
-
- local strings
- if (( $# == 0 )); then
- unset IFS
- while read -r x; do
- strings+=( "$x" )
- done
- else
- strings=( "$@" )
- fi
-
- if $new_file; then
# fix files with no newline at the end.
# the following command won't work right on them otherwise.
# e = run script, $a\ means append following text, but there is none,
return 1
fi
fi
+
+ local strings line
+ if (( $# == 0 )); then
+ unset IFS
+ while read -r line; do
+ strings+=( "$line" )
+ done
+ else
+ strings=( "$@" )
+ fi
+
if ! $new_file; then
if [[ ! -r $file ]]; then
echo "appendu error: cannot read or write $file"
echo "appendu error: cannot read or write $file"
return 1
fi
- fi
-
- local strings
- if (( $# == 0 )); then
- unset IFS
- while read -r x; do
- strings+=( "$x" )
- done
- else
- strings=( "$@" )
- fi
-
- if $new_file; then
# fix files with no newline at the end.
# the following command won't work right on them otherwise.
# e = run script, $a\ means append following text, but there is none,
#!/bin/bash -l
x=$(mktemp)
appendu $x<<'EOF'
-abc
-
-*!@#$^&*))0_)()?><M;sdf234
-
+aa
+bb
EOF
y=$(mktemp)
tee -a $y<<'EOF'
-abc
-
-*!@#$^&*))0_)()?><M;sdf234
-
+aa
+bb
EOF
-output=$(appendu $x<<'EOF'
-foo
-abc
-*(@#$%)
+output="$(
+appendu $x<<'EOF'
+cc
+aa
+caa
+bb
-*!@#$^&*))0_)()?><M;sdf234
+dd
EOF
-)
+)"
+
+good_output='cc
+caa
-good_output='foo
-*(@#$%)'
+dd'
[[ $output == "$good_output" ]] || { echo check1 failed; echo "$output != $good_output"; }
diff $x $y || echo check2 failed diffing $x and $y
-output=$(appendu $x "abc
-bd" "abc")
+output=$(appendu $x "aa
+ee" "bb")
-good_output="abc
-bd"
+good_output="aa
+ee"
[[ $output == $good_output ]] || { echo check3 failed; echo "$output != $good_output"; }