X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=appendu-function;h=35f16eb13a89514d939e945c39c1615648cdbfc8;hb=ff367964d27678cbbc93aff541e3b45274919668;hp=8b03b0fb5f77af89f95eb5bdb83a33d8f4c52398;hpb=676dcfe6e8836e8771943f9d075e2da6877aaf55;p=tee-unique diff --git a/appendu-function b/appendu-function index 8b03b0f..35f16eb 100644 --- a/appendu-function +++ b/appendu-function @@ -72,12 +72,16 @@ LINE_SETs are treated the same. # e = run script, $a\ means append following text, but there is none, # so sed only does what it always does when it was supposed to modify a file, # which is append a newline if there was none. - sed -ie '$a\' "$file" + sed -i '$a\' "$file" # command substitution removes any trailing newlines, so we have to add # a non-newline ending, we randomly chose "b", then remove it. - local content=$(cat "$file"; echo b) content=${content%b} + local content=$(cat "$file"; echo b) + content=${content%b} fi + local reset_extglob=false + ! shopt extglob >/dev/null && reset_extglob=true + shopt -s extglob # we aren't using regex because we want to match strings, # but we also want our match to start at the beginning of a line, # or the beginning of the file, and to end at a line ending. @@ -96,5 +100,6 @@ LINE_SETs are treated the same. fi fi done + $reset_extglob && shopt -u extglob return 0 }