#!/bin/bash
# trims trailing spaces and tabs from file, using awk utility
function remove_trail() {
[ ! $# -lt 2 ] || { echo "Usage: $FUNCNAME file-to-trim out-file"; return 1; }
# args
in="$1"
out="$2"
# this check works fine...
[ -f "$in" ] && return 0 || { echo "File \""$in"\" does not exist."; return 1; }
# substitute tabs and spaces for nothing on $in arg, then output result to $out
awk '{ sub(/[ \t]+$/, ""); print }' "$in" >tmp && mv tmp "$out"
#however, after previous line I don't get my tmp file nor my $out file created.. WHY :O???
# give user a friendly message
echo 'Processing done.. Check your '"$out"' file.'
}
this function is defined in .bashrc
, so I could use it daily as a kind of builtin.. so when I open shell I type remove_trail file1
file2
to get file2
written from file1
+removed_trailing_spaces.
My question is: Why I am not getting tmp and $out files created in my dir?