Debian Codegraph @

Utilities/Maintenance/strip-trailing-whitespace

raw
1 #!/bin/bash
2
3 # strip trailing whitespaces from filenames sent to stdin or as args
4
5 if which tempfile &>/dev/null; then
6 TEMPMAKER=tempfile
7 elif which mktemp &>/dev/null; then
8 TEMPMAKER=mktemp
9 else
10 echo "Cannot find tempfile program." 2>&1
11 exit 1
12 fi
13
14 MYTEMP=$($TEMPMAKER)
15 trap 'rm -f $MYTEMP' SIGINT SIGTERM
16
17 stripit() {
18 echo "stripping $1"
19 sed 's/[ \t]*$//' "$1" > $MYTEMP
20 cp $MYTEMP "$1"
21 }
22
23 if [ $# -gt 0 ]; then
24 while [ "$1" != "" ]; do
25 stripit $1
26 shift
27 done
28 else
29 while read -t 2; do
30 stripit $REPLY
31 done
32 fi
33
34 rm $MYTEMP