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