Permalink
Browse files

improve deleteMatchLine.sh and standard-funcs-sh.

  • Loading branch information...
1 parent 118a3f4 commit 63da7b8f635757caa96af6a0cbe6efd8f0ce08d4 @soarpenguin committed Feb 13, 2014
Showing with 28 additions and 9 deletions.
  1. +23 −4 bashrc/deleteMatchLine.sh
  2. +5 −5 bashrc/standard-funcs-sh
View
@@ -6,15 +6,34 @@ if [ $# -ne 2 ]; then
fi
file=$1
-all_line_sed=$2
+sourcefile=$2
+
+die()
+{
+ result=$1
+ shift
+ printf "%s\n" "$*" >&2
+ exit $result
+}
+
+checkfile()
+{
+ [ -n $1 ] || die 1 "file name is null."
+ [ -f $1 ] || die 1 "check existence of file: $1."
+}
+
+checkfile $file
+checkfile $sourcefile
for line in `cat ${file}`
do
- fgrep "${line}" ${all_line_sed} &>/dev/null
+ fgrep "${line}" ${sourcefile} &>/dev/null
if [ $? -ne 0 ];then
continue
fi
- sed -e "/${line}/d" ${all_line_sed} >${all_line_sed}.tmp
- mv ${all_line_sed}.tmp ${all_line_sed}
+ sed -e "/${line}/d" ${sourcefile} >${sourcefile}.tmp
+ mv ${sourcefile}.tmp ${sourcefile}
done
+
+
View
@@ -102,17 +102,17 @@ arg()
esac
}
-# Some error messages
-error_no_arg () { die "option ${1%%=*} does not take any arguments"; }
-error_missing_arg () { die "option ${1%%=*} takes an argument"; }
-
die() {
result=$1
shift
printf "%s\n" "$*" >&2
exit $result
}
+# Some error messages
+error_no_arg () { die 1 "option ${1%%=*} does not take any arguments"; }
+error_missing_arg () { die 1 "option ${1%%=*} takes an argument"; }
+
_show_date()
{
oldIFS=$IFS ## Save old value of IFS
@@ -184,7 +184,7 @@ date_vars()
export datestamp MonthAbbrev DayOfWeek DayNum
}
-is_num()
+_is_num()
{
case $1 in
*[!0-9]*) return 5 ;; ## Fail is any character is not a digit from 0 to 9

0 comments on commit 63da7b8

Please sign in to comment.