rajout fonction fileMustContainsMoreNItem
fix fonction commandOutput
This commit is contained in:
28
functions.sh
28
functions.sh
@@ -119,7 +119,7 @@ function fileMustContains {
|
||||
shift
|
||||
string=$@
|
||||
if [ ! -f $file ] ; then echo -ne "0;" ; return 0 ;fi
|
||||
if ( grep -i -qE "${string}" $file ) ;
|
||||
if ( grep -i -qE -- "${string}" $file ) ;
|
||||
then echo -ne "1;"
|
||||
else
|
||||
echo -ne "0;"
|
||||
@@ -140,6 +140,25 @@ function fileCountPattern {
|
||||
e "$num"
|
||||
}
|
||||
|
||||
# Ok if file contains at least N pattern
|
||||
# arg1: file
|
||||
# arg2: num of expected item
|
||||
# arg3: pattern
|
||||
function fileMustContainsMoreNItem {
|
||||
file=$1
|
||||
n=$2
|
||||
shift
|
||||
shift
|
||||
string=$@
|
||||
if [ ! -f $file ] ; then echo -ne "0;" ; return 0 ;fi
|
||||
num=$(grep -ciE "${string}" $file )
|
||||
if [ $num -ge $n ] ;
|
||||
then echo -ne "1;"
|
||||
else
|
||||
echo -ne "0;"
|
||||
fi
|
||||
}
|
||||
|
||||
# Ok if file contains N pattern
|
||||
# arg1: file
|
||||
# arg2: num of expected item
|
||||
@@ -196,7 +215,7 @@ function addHeader {
|
||||
# get file content
|
||||
# arg1: file to read
|
||||
function getFileContent {
|
||||
test -f $1 && content="$(cat $1 | sed 's/\n//');"
|
||||
test -f $1 && content="$(cat $1 | sed 's/\n//');" || content="NULL;"
|
||||
echo -ne "${content}"
|
||||
}
|
||||
|
||||
@@ -283,9 +302,8 @@ function commandOutput {
|
||||
chroot=$1
|
||||
shift
|
||||
command="$@"
|
||||
result=$(chroot ${chroot} bash -c "$command" 2> /dev/null)
|
||||
ret=$?
|
||||
if [ $ret -eq 0 ] ; then e ${result:=0} ; else e 0 ; fi
|
||||
result=$(chroot ${chroot} bash -c "$command" 2>&1)
|
||||
e "$result"
|
||||
}
|
||||
|
||||
# get num of files in given dir
|
||||
|
||||
Reference in New Issue
Block a user