You can use the in place option -i
of sed
for Linux and Unix:
sed -i 's/[ ]*$//' "$1"
Be aware the expression will delete trailing t
's on OSX (you can use gsed
to avoid this problem). It may delete them on BSD too.
If you don't have gsed, here is the correct (but hard-to-read) sed syntax on OSX:
sed -i '' -E 's/[ '$''']+$//' "$1"
Three single-quoted strings ultimately become concatenated into a single argument/expression. There is no concatenation operator in bash, you just place strings one after the other with no space in between.
The $''
resolves as a literal tab-character in bash (using ANSI-C quoting), so the tab is correctly concatenated into the expression.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…