aboutsummaryrefslogtreecommitdiff
path: root/bin/stws.sh
diff options
context:
space:
mode:
Diffstat (limited to 'bin/stws.sh')
-rw-r--r--bin/stws.sh18
1 files changed, 18 insertions, 0 deletions
diff --git a/bin/stws.sh b/bin/stws.sh
new file mode 100644
index 00000000..ce2c14d0
--- /dev/null
+++ b/bin/stws.sh
@@ -0,0 +1,18 @@
+# Strip trailing spaces on one or more files
+
+# Check arguments
+if [ "$#" -eq 0 ] ; then
+ printf >&2 'stws: Need a filename\n'
+ exit 2
+fi
+
+# Iterate over arguments and apply the same ed(1) script to each of them
+for fn ; do
+ ed -s -- "$fn" <<'EOF' || ex=1
+g/ *$/ s/ *$//
+w
+EOF
+done
+
+# If any of the ed(1) commands failed, we should exit with 1
+exit "${ex:-0}"