#!/bin/bash # . Var=var_value name_of_var=Var # . echo "name_of_var = $name_of_var" # , eval. eval val=\$${name_of_var} echo "Now val = $val" # : # bash, 2 # , ksh val=${!name_of_var} echo "by new version now val= $val"
# varName1 varName2 … varNameN => varRes1 varRes2 … varResN varValIn11 varValIn21 … varValInN1 => varVRes11 varRes21 … varResN1 varValIn12 varValIn22 … varValInN2 => varVRes12 varRes22 … varResN2 … varValIn1n varValIn2n … varValInNn => varVRes1n varRes2n … varResNn <ERROR>echo “error message”;exit; => varRes1 Err varRes2 Err … varResNErr
, => .
.
:
<?> - ; <_>- ; <.>- .
, , , .
, bash , . .
, .
, , , .
.
, . () , .
, , - () .
:
Speed= Sign= State=
, => .
.
:
<?> - ; <_>- ; <.>- .
, , , .
, bash , . .
, .
, , , .
.
, . () , .
, , - () .
:
Speed= Sign= State=
, => .
.
:
<?> - ; <_>- ; <.>- .
, , , .
, bash , . .
, .
, , , .
.
, . () , .
, , - () .
:
Speed= Sign= State=
, => .
.
:
<?> - ; <_>- ; <.>- .
, , , .
, bash , . .
, .
, , , .
.
, . () , .
, , - () .
:
Speed= Sign= State=
, => .
.
:
<?> - ; <_>- ; <.>- .
, , , .
, bash , . .
, .
, , , .
.
, . () , .
, , - () .
:
Speed= Sign= State=
, => .
.
:
<?> - ; <_>- ; <.>- .
, , , .
, bash , . .
, .
, , , .
.
, . () , .
, , - () .
:
Speed= Sign= State=
, => .
.
:
<?> - ; <_>- ; <.>- .
, , , .
, bash , . .
, .
, , , .
.
, . () , .
, , - () .
:
Speed= Sign= State=
, => .
.
:
<?> - ; <_>- ; <.>- .
, , , .
, bash , . .
, .
, , , .
.
, . () , .
, , - () .
:
Speed= Sign= State=
, => .
.
:
<?> - ; <_>- ; <.>- .
, , , .
, bash , . .
, .
, , , .
.
, . () , .
, , - () .
:
Speed= Sign= State=
, => .
.
:
<?> - ; <_>- ; <.>- .
, , , .
, bash , . .
, .
, , , .
.
, . () , .
, , - () .
:
Speed= Sign= State=
, => .
.
:
<?> - ; <_>- ; <.>- .
, , , .
, bash , . .
, .
, , , .
.
, . () , .
, , - () .
:
Speed= Sign= State=
if [[ "$Speed" == "" ]] || [[ "$Speed" == "" ]] || [[ "$Speed" == "" ]] then echo "Speed ok" else echo "Wrong Speed:${Speed}.";exit 0; fi
Conditions=' # Speed => Result => OK => OK => OK <ERROR> echo "Wrong Speed:${Speed}.";exit 0; => Error # Sign State Speed => ToDo Speed => <?> => => => => => <?> => $Speed <ERROR> echo "Wrong traffic lights"; => $ToDo $Speed '
source $HOME/bin/CheckTabel.sh # execute check and set values for vars echo "Todo=$ToDo Speed=$Speed "
Todo = slow down Speed ​​= slow
#!/bin/ksh #!/bin/ksh #/bin/bash # 11.03.2013 aap script "Test.sh" # #Speed= Speed= Sign= #Sign=" " #Sign=" " #Sign=" " State= # # Speed # if [[ "$Speed" == "" ]] || [[ "$Speed" == "" ]] || [[ "$Speed" == "" ]] then echo "Speed ok" else echo "Wrong Speed:${Speed}.";exit 0; fi Conditions=' Sign => Result => OK => OK => OK <ERROR> echo "Wrong Sign:${Sign}.";exit 0; => Error Speed => Result => OK => OK => OK <ERROR> echo "Wrong Speed:${Speed}.";exit 0; => Error Sign State Speed => ToDo Speed => <?> => => => => => <?> => $Speed <ERROR> echo "Wrong traffic lights"; => $ToDo $Speed Sign Speed => ToDo Speed => <?> => <ERROR> echo "Wrong ramp police"; => $ToDo $Speed Sign Speed => ToDo Speed => <?> => <ERROR> echo "Wrong let have road"; => $ToDo $Speed # , State <?> - # . Speed # Speed . ! Sign State Speed => ToDoAlter SpeedAlter => <?> => => => => => <?> => $Speed <?> => <?> <?> => <?> => <?> <?> => <ERROR> echo "Wrong "; => ${Speed} ' source $HOME/bin/CheckTabel.sh # execute check and set values for vars #echo "$Conditions" echo "Todo=$ToDo Speed=$Speed " echo "alternative:" echo "Todo=$ToDoAlter Speed=$SpeedAlter " exit 0
Todo = slow down Speed ​​= slow
alternative:
Todo = slow down Speed ​​= stand
#echo ifs=$IFS OLD_IFS="$IFS" IFS=$' '#
echo "${Conditions}" | while read Line do … done #while read Line
eVarLine=(`echo "$Line"`)
tmp=${eVarLine[$i]} # get name of input var eval tmp=\$$tmp # gat var value by var name eVarDatIN[${i}]=${tmp}
eDatLine=( `echo "$Line"` )
.
.
, – ? , , .
, , .
( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done echo "${LineErr}" # error command ) >> $eTmpFile # create temporary file for setup vars and show error message
. , .
# ---------- execute -------------- eISVAR=1 # its mean , that next line will with varnames source $eTmpFile #. data-file # execute file and set values for vars > $eTmpFile # erase temporary file for setup vars
tmpSetVar.sh , Result="OK"
Result="OK"
ToDo=""
Speed=""
ToDo="$ToDo"
Speed="$Speed"
echo "Wrong ramp police";
ToDo="$ToDo"
Speed="$Speed"
echo "Wrong let have road";
ToDoAlter=""
SpeedAlter=""
. – .
, .
Perl - , .
.
CheckTabel.sh #/bin/ksh #/bin/bash # # script CheckTabel.sh - check tabel data # # See on : http://www.linuxcookbook.ru/books/absguide/ch09s05.html # #12.02.2013 _aap_ created by Patratskiy Aleksey #26.02.2013 _aap_ RELAEASE work with errors, get first right parametrs #28.02.2013 _aap_ fix same problem var counts #05.03.2013 _aap_ can use without <END> # #Limits : #Comment '#' work only for first position in string #Devior TAB If parameters use TAB it can not be used #input data: Conditions # # after you can check variable "CheckTabelErrors" for errors count #exaple of var :Conditions #Conditions=' ##check stuff of vars and data #Check var parametrs #varIn1 varIn2 varIn3 varIn4 => varOut1 varOut2 #varIn1varIn1 varIn2varIn2 varIn3varIn3 varIn4varIn4 => AAPvarOut1varOut1 AAPvarOut2varOut2 #<.> <_> <> dsf => sdf sdf #<ERROR> Error `exit 1` => <> <> #<END> #' #internals Vars: eTmpFile=$HOME/tmp/tmpSetVar.sh eDIVISOR=' ' eInOutDevisor='=>' eEND='<END>' eERROR='<ERROR>' eANY='<?>' eEMPTY='<_>' eNOTEMPTY='<.>' eISVAR=1 eDeb="" eIsFind=0 ((CheckTabelErrors=0)) ((eCurLine=0)) #for ksh typeset -A eDataIN typeset -A eDataOUT typeset -A eVarIN typeset -A eVarDatIN typeset -A eVarOUT typeset -A eVarLine typeset -A eDatLine #for bash #typeset -a eDataIN #typeset -a eDataOUT #typeset -a eVarIN #typeset -a eVarDatIN #typeset -a eVarOUT #typeset -a eVarLine #typeset -a eDatLine #source $eTmpFile # erase temporary file for setap vars > $eTmpFile # erase temporary file for setap vars #echo ifs=$IFS OLD_IFS="$IFS" IFS=$' '# echo "${Conditions}" | while read Line do ((eCurLine++)) # echo "LineErr: ${eCurLine}" ;echo "Line: ${Line}" if [[ "${Line:0:1}" != "#" && "$Line" != "" && "${Line:0:${#eEND}}" != "${eEND}" ]] #skeep empty and commets lines AND with <END> then if [[ "eISVAR" -eq "1" ]] # check for var names line then eISVAR=0 eVarLine=(`echo "$Line"`) cntIn=${#eVarLine[@]} # echo ${#eVarLine[@]} ${eVarLine[@]} for (( i = 0 ; i < cntIn ; i++ )) do #get names of input vars if [ "${eVarLine[${i}]}" == "${eInOutDevisor}" ] then ((outBgn=i + 1)) break fi eVarIN[${i}]=${eVarLine[$i]} tmp=${eVarLine[$i]} # get name of input var eval tmp=\$$tmp # gat var value by var name eVarDatIN[${i}]=${tmp} # echo DEBUG Element [$i]: ${eVarLine[$i]} val=${eVarIN[${i}]} eVarDatIN=${eVarDatIN[${i}]} done # echo DEBUG outBgn=$outBgn cntIn=$cntIn if (( cntIn == 0 || outBgn == 0 )) then echo !!! Error CheckTabel.sh formating outBgn=$outBgn cntIn=$cntIn wrong eDIVISOR TAB continue fi (( j = 0 )) for (( i = $outBgn ; i < cntIn ; i++ )) do # get name of output vars # echo "${eVarLine[$i]}=Set${i}" eVarOUT[$j]=${eVarLine[$i]} ((j++)) done eIsFind=0 # not finde yet # echo eVarIN ${#eVarIN[@]}: ${eVarIN[@]} ; echo eVarOUT ${#eVarOUT[@]}: ${eVarOUT[@]} ################################################################################### else if [[ "${Line:0:${#eEND}}" == "${eEND}" ]] # check for end of sentence then # echo "END: $Line" #echo "Line: ${Line:0:${#eEND}} == " # eISVAR=1 # source $eTmpFile #. data-file # execute file and set values for vars # > $eTmpFile # erase temporary file for setap vars continue # while read Line fi # #Check for error message and error vars set # if [[ "${Line:0:${#eERROR}}" == "${eERROR}" ]] # check for ERROR of sentence then # echo "<ERROR>:${eIsFind} $Line" #echo "Line: ${Line:0:${#eEND}} == " LineErr="" if [[ "eIsFind" -eq "0" ]] then ((CheckTabelErrors++)) LineErr="${Line#${eERROR}}" #remove <Error> echo "!!! ERROR CheckTabel.sh LineErr: ${eCurLine}" #;echo "Line: ${Line}" ErrVarOut="${LineErr#*${eInOutDevisor}}" #+ ${#eInOutDevisor}+ LineErr="${LineErr%${eInOutDevisor}*}" eDataOUT=( `echo "$ErrVarOut"` ) ( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done echo "${LineErr}" # error command ) >> $eTmpFile # create temporary file for setup vars and show error message fi # ---------- execute -------------- eISVAR=1 # its mean , that next line will with varnames source $eTmpFile #. data-file # execute file and set values for vars > $eTmpFile # erase temporary file for setap vars continue # while read Line fi #for skeep all next currient tabel parametrs if [[ "eIsFind" -eq "1" ]] then continue # while read Line fi eDatLine=( `echo "$Line"` ) # echo OUT ${#eDatLine[@]} ${eDatLine[@]} cntOut=${#eDatLine[@]} if (( $cntIn != $cntOut )) then echo !!! Error CheckTabel.sh in Conditions line=${eCurLine} formating Vars $cntIn but Data $cntOut, count of parametrs not equel ! ;echo !!! ${eVarIN[@]} === ${eDatLine[@]} continue # while read Line fi # # main check for compare tabale value and var value in currient string # ((cmpCnt=0)) for (( i = 0 ; i < cntOut ; i++ )) do #get input data if [ "${eDatLine[${i}]}" == "${eInOutDevisor}" ] ; then ((outBgn=i + 1)) break fi # echo DEBUG Element [$i]: ${eDatLine[$i]} val=${!eDatLine[$i]} eDatLine=${eDatLine[${i}]} == eVarDatIN="${eVarDatIN[$i]}" if [ "${eDatLine[${i}]}" == "${eVarDatIN[$i]}" ] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eANY}" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eNOTEMPTY}" && "${eVarDatIN[$i]}" != "" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eEMPTY}" && "${eVarDatIN[$i]}" == "" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi done # echo DEBUG "$cmpCnt" == "(($outBgn - 1 ))" outBgn=$outBgn cntIn=$cntIn if (( "$cmpCnt" == "(($outBgn - 1 ))" )) # there are data in this string #${#eVarIN[@]} then (( j = 0 )) for (( i = $outBgn ; i < cntOut ; i++ )) do # get value for output vars eDataOUT[$j]=${eDatLine[$i]} # echo "DEBUG ${eVarOUT[$j]}=${eDataOUT[$j]}" ((j++)) done ( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done ) >> $eTmpFile # create temporary file for setap vars eIsFind=1 # echo OK: ${eVarIN[@]} == ${eDataIN[@]} '=>' ${eVarOUT[@]} == ${eDataOUT[@]} fi fi else #skeep empty and commets lines # echo Comment: $Line eDeb="" # for skeep warning fi done #while read Line ######################################################################3 IFS=$OLD_IFS #rm $eTmpFile
.
.
, – ? , , .
, , .
( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done echo "${LineErr}" # error command ) >> $eTmpFile # create temporary file for setup vars and show error message
. , .
# ---------- execute -------------- eISVAR=1 # its mean , that next line will with varnames source $eTmpFile #. data-file # execute file and set values for vars > $eTmpFile # erase temporary file for setup vars
tmpSetVar.sh , Result="OK"
Result="OK"
ToDo=""
Speed=""
ToDo="$ToDo"
Speed="$Speed"
echo "Wrong ramp police";
ToDo="$ToDo"
Speed="$Speed"
echo "Wrong let have road";
ToDoAlter=""
SpeedAlter=""
. – .
, .
Perl - , .
.
CheckTabel.sh #/bin/ksh #/bin/bash # # script CheckTabel.sh - check tabel data # # See on : http://www.linuxcookbook.ru/books/absguide/ch09s05.html # #12.02.2013 _aap_ created by Patratskiy Aleksey #26.02.2013 _aap_ RELAEASE work with errors, get first right parametrs #28.02.2013 _aap_ fix same problem var counts #05.03.2013 _aap_ can use without <END> # #Limits : #Comment '#' work only for first position in string #Devior TAB If parameters use TAB it can not be used #input data: Conditions # # after you can check variable "CheckTabelErrors" for errors count #exaple of var :Conditions #Conditions=' ##check stuff of vars and data #Check var parametrs #varIn1 varIn2 varIn3 varIn4 => varOut1 varOut2 #varIn1varIn1 varIn2varIn2 varIn3varIn3 varIn4varIn4 => AAPvarOut1varOut1 AAPvarOut2varOut2 #<.> <_> <> dsf => sdf sdf #<ERROR> Error `exit 1` => <> <> #<END> #' #internals Vars: eTmpFile=$HOME/tmp/tmpSetVar.sh eDIVISOR=' ' eInOutDevisor='=>' eEND='<END>' eERROR='<ERROR>' eANY='<?>' eEMPTY='<_>' eNOTEMPTY='<.>' eISVAR=1 eDeb="" eIsFind=0 ((CheckTabelErrors=0)) ((eCurLine=0)) #for ksh typeset -A eDataIN typeset -A eDataOUT typeset -A eVarIN typeset -A eVarDatIN typeset -A eVarOUT typeset -A eVarLine typeset -A eDatLine #for bash #typeset -a eDataIN #typeset -a eDataOUT #typeset -a eVarIN #typeset -a eVarDatIN #typeset -a eVarOUT #typeset -a eVarLine #typeset -a eDatLine #source $eTmpFile # erase temporary file for setap vars > $eTmpFile # erase temporary file for setap vars #echo ifs=$IFS OLD_IFS="$IFS" IFS=$' '# echo "${Conditions}" | while read Line do ((eCurLine++)) # echo "LineErr: ${eCurLine}" ;echo "Line: ${Line}" if [[ "${Line:0:1}" != "#" && "$Line" != "" && "${Line:0:${#eEND}}" != "${eEND}" ]] #skeep empty and commets lines AND with <END> then if [[ "eISVAR" -eq "1" ]] # check for var names line then eISVAR=0 eVarLine=(`echo "$Line"`) cntIn=${#eVarLine[@]} # echo ${#eVarLine[@]} ${eVarLine[@]} for (( i = 0 ; i < cntIn ; i++ )) do #get names of input vars if [ "${eVarLine[${i}]}" == "${eInOutDevisor}" ] then ((outBgn=i + 1)) break fi eVarIN[${i}]=${eVarLine[$i]} tmp=${eVarLine[$i]} # get name of input var eval tmp=\$$tmp # gat var value by var name eVarDatIN[${i}]=${tmp} # echo DEBUG Element [$i]: ${eVarLine[$i]} val=${eVarIN[${i}]} eVarDatIN=${eVarDatIN[${i}]} done # echo DEBUG outBgn=$outBgn cntIn=$cntIn if (( cntIn == 0 || outBgn == 0 )) then echo !!! Error CheckTabel.sh formating outBgn=$outBgn cntIn=$cntIn wrong eDIVISOR TAB continue fi (( j = 0 )) for (( i = $outBgn ; i < cntIn ; i++ )) do # get name of output vars # echo "${eVarLine[$i]}=Set${i}" eVarOUT[$j]=${eVarLine[$i]} ((j++)) done eIsFind=0 # not finde yet # echo eVarIN ${#eVarIN[@]}: ${eVarIN[@]} ; echo eVarOUT ${#eVarOUT[@]}: ${eVarOUT[@]} ################################################################################### else if [[ "${Line:0:${#eEND}}" == "${eEND}" ]] # check for end of sentence then # echo "END: $Line" #echo "Line: ${Line:0:${#eEND}} == " # eISVAR=1 # source $eTmpFile #. data-file # execute file and set values for vars # > $eTmpFile # erase temporary file for setap vars continue # while read Line fi # #Check for error message and error vars set # if [[ "${Line:0:${#eERROR}}" == "${eERROR}" ]] # check for ERROR of sentence then # echo "<ERROR>:${eIsFind} $Line" #echo "Line: ${Line:0:${#eEND}} == " LineErr="" if [[ "eIsFind" -eq "0" ]] then ((CheckTabelErrors++)) LineErr="${Line#${eERROR}}" #remove <Error> echo "!!! ERROR CheckTabel.sh LineErr: ${eCurLine}" #;echo "Line: ${Line}" ErrVarOut="${LineErr#*${eInOutDevisor}}" #+ ${#eInOutDevisor}+ LineErr="${LineErr%${eInOutDevisor}*}" eDataOUT=( `echo "$ErrVarOut"` ) ( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done echo "${LineErr}" # error command ) >> $eTmpFile # create temporary file for setup vars and show error message fi # ---------- execute -------------- eISVAR=1 # its mean , that next line will with varnames source $eTmpFile #. data-file # execute file and set values for vars > $eTmpFile # erase temporary file for setap vars continue # while read Line fi #for skeep all next currient tabel parametrs if [[ "eIsFind" -eq "1" ]] then continue # while read Line fi eDatLine=( `echo "$Line"` ) # echo OUT ${#eDatLine[@]} ${eDatLine[@]} cntOut=${#eDatLine[@]} if (( $cntIn != $cntOut )) then echo !!! Error CheckTabel.sh in Conditions line=${eCurLine} formating Vars $cntIn but Data $cntOut, count of parametrs not equel ! ;echo !!! ${eVarIN[@]} === ${eDatLine[@]} continue # while read Line fi # # main check for compare tabale value and var value in currient string # ((cmpCnt=0)) for (( i = 0 ; i < cntOut ; i++ )) do #get input data if [ "${eDatLine[${i}]}" == "${eInOutDevisor}" ] ; then ((outBgn=i + 1)) break fi # echo DEBUG Element [$i]: ${eDatLine[$i]} val=${!eDatLine[$i]} eDatLine=${eDatLine[${i}]} == eVarDatIN="${eVarDatIN[$i]}" if [ "${eDatLine[${i}]}" == "${eVarDatIN[$i]}" ] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eANY}" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eNOTEMPTY}" && "${eVarDatIN[$i]}" != "" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eEMPTY}" && "${eVarDatIN[$i]}" == "" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi done # echo DEBUG "$cmpCnt" == "(($outBgn - 1 ))" outBgn=$outBgn cntIn=$cntIn if (( "$cmpCnt" == "(($outBgn - 1 ))" )) # there are data in this string #${#eVarIN[@]} then (( j = 0 )) for (( i = $outBgn ; i < cntOut ; i++ )) do # get value for output vars eDataOUT[$j]=${eDatLine[$i]} # echo "DEBUG ${eVarOUT[$j]}=${eDataOUT[$j]}" ((j++)) done ( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done ) >> $eTmpFile # create temporary file for setap vars eIsFind=1 # echo OK: ${eVarIN[@]} == ${eDataIN[@]} '=>' ${eVarOUT[@]} == ${eDataOUT[@]} fi fi else #skeep empty and commets lines # echo Comment: $Line eDeb="" # for skeep warning fi done #while read Line ######################################################################3 IFS=$OLD_IFS #rm $eTmpFile
.
.
, – ? , , .
, , .
( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done echo "${LineErr}" # error command ) >> $eTmpFile # create temporary file for setup vars and show error message
. , .
# ---------- execute -------------- eISVAR=1 # its mean , that next line will with varnames source $eTmpFile #. data-file # execute file and set values for vars > $eTmpFile # erase temporary file for setup vars
tmpSetVar.sh , Result="OK"
Result="OK"
ToDo=""
Speed=""
ToDo="$ToDo"
Speed="$Speed"
echo "Wrong ramp police";
ToDo="$ToDo"
Speed="$Speed"
echo "Wrong let have road";
ToDoAlter=""
SpeedAlter=""
. – .
, .
Perl - , .
.
CheckTabel.sh #/bin/ksh #/bin/bash # # script CheckTabel.sh - check tabel data # # See on : http://www.linuxcookbook.ru/books/absguide/ch09s05.html # #12.02.2013 _aap_ created by Patratskiy Aleksey #26.02.2013 _aap_ RELAEASE work with errors, get first right parametrs #28.02.2013 _aap_ fix same problem var counts #05.03.2013 _aap_ can use without <END> # #Limits : #Comment '#' work only for first position in string #Devior TAB If parameters use TAB it can not be used #input data: Conditions # # after you can check variable "CheckTabelErrors" for errors count #exaple of var :Conditions #Conditions=' ##check stuff of vars and data #Check var parametrs #varIn1 varIn2 varIn3 varIn4 => varOut1 varOut2 #varIn1varIn1 varIn2varIn2 varIn3varIn3 varIn4varIn4 => AAPvarOut1varOut1 AAPvarOut2varOut2 #<.> <_> <> dsf => sdf sdf #<ERROR> Error `exit 1` => <> <> #<END> #' #internals Vars: eTmpFile=$HOME/tmp/tmpSetVar.sh eDIVISOR=' ' eInOutDevisor='=>' eEND='<END>' eERROR='<ERROR>' eANY='<?>' eEMPTY='<_>' eNOTEMPTY='<.>' eISVAR=1 eDeb="" eIsFind=0 ((CheckTabelErrors=0)) ((eCurLine=0)) #for ksh typeset -A eDataIN typeset -A eDataOUT typeset -A eVarIN typeset -A eVarDatIN typeset -A eVarOUT typeset -A eVarLine typeset -A eDatLine #for bash #typeset -a eDataIN #typeset -a eDataOUT #typeset -a eVarIN #typeset -a eVarDatIN #typeset -a eVarOUT #typeset -a eVarLine #typeset -a eDatLine #source $eTmpFile # erase temporary file for setap vars > $eTmpFile # erase temporary file for setap vars #echo ifs=$IFS OLD_IFS="$IFS" IFS=$' '# echo "${Conditions}" | while read Line do ((eCurLine++)) # echo "LineErr: ${eCurLine}" ;echo "Line: ${Line}" if [[ "${Line:0:1}" != "#" && "$Line" != "" && "${Line:0:${#eEND}}" != "${eEND}" ]] #skeep empty and commets lines AND with <END> then if [[ "eISVAR" -eq "1" ]] # check for var names line then eISVAR=0 eVarLine=(`echo "$Line"`) cntIn=${#eVarLine[@]} # echo ${#eVarLine[@]} ${eVarLine[@]} for (( i = 0 ; i < cntIn ; i++ )) do #get names of input vars if [ "${eVarLine[${i}]}" == "${eInOutDevisor}" ] then ((outBgn=i + 1)) break fi eVarIN[${i}]=${eVarLine[$i]} tmp=${eVarLine[$i]} # get name of input var eval tmp=\$$tmp # gat var value by var name eVarDatIN[${i}]=${tmp} # echo DEBUG Element [$i]: ${eVarLine[$i]} val=${eVarIN[${i}]} eVarDatIN=${eVarDatIN[${i}]} done # echo DEBUG outBgn=$outBgn cntIn=$cntIn if (( cntIn == 0 || outBgn == 0 )) then echo !!! Error CheckTabel.sh formating outBgn=$outBgn cntIn=$cntIn wrong eDIVISOR TAB continue fi (( j = 0 )) for (( i = $outBgn ; i < cntIn ; i++ )) do # get name of output vars # echo "${eVarLine[$i]}=Set${i}" eVarOUT[$j]=${eVarLine[$i]} ((j++)) done eIsFind=0 # not finde yet # echo eVarIN ${#eVarIN[@]}: ${eVarIN[@]} ; echo eVarOUT ${#eVarOUT[@]}: ${eVarOUT[@]} ################################################################################### else if [[ "${Line:0:${#eEND}}" == "${eEND}" ]] # check for end of sentence then # echo "END: $Line" #echo "Line: ${Line:0:${#eEND}} == " # eISVAR=1 # source $eTmpFile #. data-file # execute file and set values for vars # > $eTmpFile # erase temporary file for setap vars continue # while read Line fi # #Check for error message and error vars set # if [[ "${Line:0:${#eERROR}}" == "${eERROR}" ]] # check for ERROR of sentence then # echo "<ERROR>:${eIsFind} $Line" #echo "Line: ${Line:0:${#eEND}} == " LineErr="" if [[ "eIsFind" -eq "0" ]] then ((CheckTabelErrors++)) LineErr="${Line#${eERROR}}" #remove <Error> echo "!!! ERROR CheckTabel.sh LineErr: ${eCurLine}" #;echo "Line: ${Line}" ErrVarOut="${LineErr#*${eInOutDevisor}}" #+ ${#eInOutDevisor}+ LineErr="${LineErr%${eInOutDevisor}*}" eDataOUT=( `echo "$ErrVarOut"` ) ( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done echo "${LineErr}" # error command ) >> $eTmpFile # create temporary file for setup vars and show error message fi # ---------- execute -------------- eISVAR=1 # its mean , that next line will with varnames source $eTmpFile #. data-file # execute file and set values for vars > $eTmpFile # erase temporary file for setap vars continue # while read Line fi #for skeep all next currient tabel parametrs if [[ "eIsFind" -eq "1" ]] then continue # while read Line fi eDatLine=( `echo "$Line"` ) # echo OUT ${#eDatLine[@]} ${eDatLine[@]} cntOut=${#eDatLine[@]} if (( $cntIn != $cntOut )) then echo !!! Error CheckTabel.sh in Conditions line=${eCurLine} formating Vars $cntIn but Data $cntOut, count of parametrs not equel ! ;echo !!! ${eVarIN[@]} === ${eDatLine[@]} continue # while read Line fi # # main check for compare tabale value and var value in currient string # ((cmpCnt=0)) for (( i = 0 ; i < cntOut ; i++ )) do #get input data if [ "${eDatLine[${i}]}" == "${eInOutDevisor}" ] ; then ((outBgn=i + 1)) break fi # echo DEBUG Element [$i]: ${eDatLine[$i]} val=${!eDatLine[$i]} eDatLine=${eDatLine[${i}]} == eVarDatIN="${eVarDatIN[$i]}" if [ "${eDatLine[${i}]}" == "${eVarDatIN[$i]}" ] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eANY}" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eNOTEMPTY}" && "${eVarDatIN[$i]}" != "" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eEMPTY}" && "${eVarDatIN[$i]}" == "" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi done # echo DEBUG "$cmpCnt" == "(($outBgn - 1 ))" outBgn=$outBgn cntIn=$cntIn if (( "$cmpCnt" == "(($outBgn - 1 ))" )) # there are data in this string #${#eVarIN[@]} then (( j = 0 )) for (( i = $outBgn ; i < cntOut ; i++ )) do # get value for output vars eDataOUT[$j]=${eDatLine[$i]} # echo "DEBUG ${eVarOUT[$j]}=${eDataOUT[$j]}" ((j++)) done ( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done ) >> $eTmpFile # create temporary file for setap vars eIsFind=1 # echo OK: ${eVarIN[@]} == ${eDataIN[@]} '=>' ${eVarOUT[@]} == ${eDataOUT[@]} fi fi else #skeep empty and commets lines # echo Comment: $Line eDeb="" # for skeep warning fi done #while read Line ######################################################################3 IFS=$OLD_IFS #rm $eTmpFile
.
.
, – ? , , .
, , .
( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done echo "${LineErr}" # error command ) >> $eTmpFile # create temporary file for setup vars and show error message
. , .
# ---------- execute -------------- eISVAR=1 # its mean , that next line will with varnames source $eTmpFile #. data-file # execute file and set values for vars > $eTmpFile # erase temporary file for setup vars
tmpSetVar.sh , Result="OK"
Result="OK"
ToDo=""
Speed=""
ToDo="$ToDo"
Speed="$Speed"
echo "Wrong ramp police";
ToDo="$ToDo"
Speed="$Speed"
echo "Wrong let have road";
ToDoAlter=""
SpeedAlter=""
. – .
, .
Perl - , .
.
CheckTabel.sh #/bin/ksh #/bin/bash # # script CheckTabel.sh - check tabel data # # See on : http://www.linuxcookbook.ru/books/absguide/ch09s05.html # #12.02.2013 _aap_ created by Patratskiy Aleksey #26.02.2013 _aap_ RELAEASE work with errors, get first right parametrs #28.02.2013 _aap_ fix same problem var counts #05.03.2013 _aap_ can use without <END> # #Limits : #Comment '#' work only for first position in string #Devior TAB If parameters use TAB it can not be used #input data: Conditions # # after you can check variable "CheckTabelErrors" for errors count #exaple of var :Conditions #Conditions=' ##check stuff of vars and data #Check var parametrs #varIn1 varIn2 varIn3 varIn4 => varOut1 varOut2 #varIn1varIn1 varIn2varIn2 varIn3varIn3 varIn4varIn4 => AAPvarOut1varOut1 AAPvarOut2varOut2 #<.> <_> <> dsf => sdf sdf #<ERROR> Error `exit 1` => <> <> #<END> #' #internals Vars: eTmpFile=$HOME/tmp/tmpSetVar.sh eDIVISOR=' ' eInOutDevisor='=>' eEND='<END>' eERROR='<ERROR>' eANY='<?>' eEMPTY='<_>' eNOTEMPTY='<.>' eISVAR=1 eDeb="" eIsFind=0 ((CheckTabelErrors=0)) ((eCurLine=0)) #for ksh typeset -A eDataIN typeset -A eDataOUT typeset -A eVarIN typeset -A eVarDatIN typeset -A eVarOUT typeset -A eVarLine typeset -A eDatLine #for bash #typeset -a eDataIN #typeset -a eDataOUT #typeset -a eVarIN #typeset -a eVarDatIN #typeset -a eVarOUT #typeset -a eVarLine #typeset -a eDatLine #source $eTmpFile # erase temporary file for setap vars > $eTmpFile # erase temporary file for setap vars #echo ifs=$IFS OLD_IFS="$IFS" IFS=$' '# echo "${Conditions}" | while read Line do ((eCurLine++)) # echo "LineErr: ${eCurLine}" ;echo "Line: ${Line}" if [[ "${Line:0:1}" != "#" && "$Line" != "" && "${Line:0:${#eEND}}" != "${eEND}" ]] #skeep empty and commets lines AND with <END> then if [[ "eISVAR" -eq "1" ]] # check for var names line then eISVAR=0 eVarLine=(`echo "$Line"`) cntIn=${#eVarLine[@]} # echo ${#eVarLine[@]} ${eVarLine[@]} for (( i = 0 ; i < cntIn ; i++ )) do #get names of input vars if [ "${eVarLine[${i}]}" == "${eInOutDevisor}" ] then ((outBgn=i + 1)) break fi eVarIN[${i}]=${eVarLine[$i]} tmp=${eVarLine[$i]} # get name of input var eval tmp=\$$tmp # gat var value by var name eVarDatIN[${i}]=${tmp} # echo DEBUG Element [$i]: ${eVarLine[$i]} val=${eVarIN[${i}]} eVarDatIN=${eVarDatIN[${i}]} done # echo DEBUG outBgn=$outBgn cntIn=$cntIn if (( cntIn == 0 || outBgn == 0 )) then echo !!! Error CheckTabel.sh formating outBgn=$outBgn cntIn=$cntIn wrong eDIVISOR TAB continue fi (( j = 0 )) for (( i = $outBgn ; i < cntIn ; i++ )) do # get name of output vars # echo "${eVarLine[$i]}=Set${i}" eVarOUT[$j]=${eVarLine[$i]} ((j++)) done eIsFind=0 # not finde yet # echo eVarIN ${#eVarIN[@]}: ${eVarIN[@]} ; echo eVarOUT ${#eVarOUT[@]}: ${eVarOUT[@]} ################################################################################### else if [[ "${Line:0:${#eEND}}" == "${eEND}" ]] # check for end of sentence then # echo "END: $Line" #echo "Line: ${Line:0:${#eEND}} == " # eISVAR=1 # source $eTmpFile #. data-file # execute file and set values for vars # > $eTmpFile # erase temporary file for setap vars continue # while read Line fi # #Check for error message and error vars set # if [[ "${Line:0:${#eERROR}}" == "${eERROR}" ]] # check for ERROR of sentence then # echo "<ERROR>:${eIsFind} $Line" #echo "Line: ${Line:0:${#eEND}} == " LineErr="" if [[ "eIsFind" -eq "0" ]] then ((CheckTabelErrors++)) LineErr="${Line#${eERROR}}" #remove <Error> echo "!!! ERROR CheckTabel.sh LineErr: ${eCurLine}" #;echo "Line: ${Line}" ErrVarOut="${LineErr#*${eInOutDevisor}}" #+ ${#eInOutDevisor}+ LineErr="${LineErr%${eInOutDevisor}*}" eDataOUT=( `echo "$ErrVarOut"` ) ( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done echo "${LineErr}" # error command ) >> $eTmpFile # create temporary file for setup vars and show error message fi # ---------- execute -------------- eISVAR=1 # its mean , that next line will with varnames source $eTmpFile #. data-file # execute file and set values for vars > $eTmpFile # erase temporary file for setap vars continue # while read Line fi #for skeep all next currient tabel parametrs if [[ "eIsFind" -eq "1" ]] then continue # while read Line fi eDatLine=( `echo "$Line"` ) # echo OUT ${#eDatLine[@]} ${eDatLine[@]} cntOut=${#eDatLine[@]} if (( $cntIn != $cntOut )) then echo !!! Error CheckTabel.sh in Conditions line=${eCurLine} formating Vars $cntIn but Data $cntOut, count of parametrs not equel ! ;echo !!! ${eVarIN[@]} === ${eDatLine[@]} continue # while read Line fi # # main check for compare tabale value and var value in currient string # ((cmpCnt=0)) for (( i = 0 ; i < cntOut ; i++ )) do #get input data if [ "${eDatLine[${i}]}" == "${eInOutDevisor}" ] ; then ((outBgn=i + 1)) break fi # echo DEBUG Element [$i]: ${eDatLine[$i]} val=${!eDatLine[$i]} eDatLine=${eDatLine[${i}]} == eVarDatIN="${eVarDatIN[$i]}" if [ "${eDatLine[${i}]}" == "${eVarDatIN[$i]}" ] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eANY}" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eNOTEMPTY}" && "${eVarDatIN[$i]}" != "" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eEMPTY}" && "${eVarDatIN[$i]}" == "" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi done # echo DEBUG "$cmpCnt" == "(($outBgn - 1 ))" outBgn=$outBgn cntIn=$cntIn if (( "$cmpCnt" == "(($outBgn - 1 ))" )) # there are data in this string #${#eVarIN[@]} then (( j = 0 )) for (( i = $outBgn ; i < cntOut ; i++ )) do # get value for output vars eDataOUT[$j]=${eDatLine[$i]} # echo "DEBUG ${eVarOUT[$j]}=${eDataOUT[$j]}" ((j++)) done ( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done ) >> $eTmpFile # create temporary file for setap vars eIsFind=1 # echo OK: ${eVarIN[@]} == ${eDataIN[@]} '=>' ${eVarOUT[@]} == ${eDataOUT[@]} fi fi else #skeep empty and commets lines # echo Comment: $Line eDeb="" # for skeep warning fi done #while read Line ######################################################################3 IFS=$OLD_IFS #rm $eTmpFile
.
.
, – ? , , .
, , .
( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done echo "${LineErr}" # error command ) >> $eTmpFile # create temporary file for setup vars and show error message
. , .
# ---------- execute -------------- eISVAR=1 # its mean , that next line will with varnames source $eTmpFile #. data-file # execute file and set values for vars > $eTmpFile # erase temporary file for setup vars
tmpSetVar.sh , Result="OK"
Result="OK"
ToDo=""
Speed=""
ToDo="$ToDo"
Speed="$Speed"
echo "Wrong ramp police";
ToDo="$ToDo"
Speed="$Speed"
echo "Wrong let have road";
ToDoAlter=""
SpeedAlter=""
. – .
, .
Perl - , .
.
CheckTabel.sh #/bin/ksh #/bin/bash # # script CheckTabel.sh - check tabel data # # See on : http://www.linuxcookbook.ru/books/absguide/ch09s05.html # #12.02.2013 _aap_ created by Patratskiy Aleksey #26.02.2013 _aap_ RELAEASE work with errors, get first right parametrs #28.02.2013 _aap_ fix same problem var counts #05.03.2013 _aap_ can use without <END> # #Limits : #Comment '#' work only for first position in string #Devior TAB If parameters use TAB it can not be used #input data: Conditions # # after you can check variable "CheckTabelErrors" for errors count #exaple of var :Conditions #Conditions=' ##check stuff of vars and data #Check var parametrs #varIn1 varIn2 varIn3 varIn4 => varOut1 varOut2 #varIn1varIn1 varIn2varIn2 varIn3varIn3 varIn4varIn4 => AAPvarOut1varOut1 AAPvarOut2varOut2 #<.> <_> <> dsf => sdf sdf #<ERROR> Error `exit 1` => <> <> #<END> #' #internals Vars: eTmpFile=$HOME/tmp/tmpSetVar.sh eDIVISOR=' ' eInOutDevisor='=>' eEND='<END>' eERROR='<ERROR>' eANY='<?>' eEMPTY='<_>' eNOTEMPTY='<.>' eISVAR=1 eDeb="" eIsFind=0 ((CheckTabelErrors=0)) ((eCurLine=0)) #for ksh typeset -A eDataIN typeset -A eDataOUT typeset -A eVarIN typeset -A eVarDatIN typeset -A eVarOUT typeset -A eVarLine typeset -A eDatLine #for bash #typeset -a eDataIN #typeset -a eDataOUT #typeset -a eVarIN #typeset -a eVarDatIN #typeset -a eVarOUT #typeset -a eVarLine #typeset -a eDatLine #source $eTmpFile # erase temporary file for setap vars > $eTmpFile # erase temporary file for setap vars #echo ifs=$IFS OLD_IFS="$IFS" IFS=$' '# echo "${Conditions}" | while read Line do ((eCurLine++)) # echo "LineErr: ${eCurLine}" ;echo "Line: ${Line}" if [[ "${Line:0:1}" != "#" && "$Line" != "" && "${Line:0:${#eEND}}" != "${eEND}" ]] #skeep empty and commets lines AND with <END> then if [[ "eISVAR" -eq "1" ]] # check for var names line then eISVAR=0 eVarLine=(`echo "$Line"`) cntIn=${#eVarLine[@]} # echo ${#eVarLine[@]} ${eVarLine[@]} for (( i = 0 ; i < cntIn ; i++ )) do #get names of input vars if [ "${eVarLine[${i}]}" == "${eInOutDevisor}" ] then ((outBgn=i + 1)) break fi eVarIN[${i}]=${eVarLine[$i]} tmp=${eVarLine[$i]} # get name of input var eval tmp=\$$tmp # gat var value by var name eVarDatIN[${i}]=${tmp} # echo DEBUG Element [$i]: ${eVarLine[$i]} val=${eVarIN[${i}]} eVarDatIN=${eVarDatIN[${i}]} done # echo DEBUG outBgn=$outBgn cntIn=$cntIn if (( cntIn == 0 || outBgn == 0 )) then echo !!! Error CheckTabel.sh formating outBgn=$outBgn cntIn=$cntIn wrong eDIVISOR TAB continue fi (( j = 0 )) for (( i = $outBgn ; i < cntIn ; i++ )) do # get name of output vars # echo "${eVarLine[$i]}=Set${i}" eVarOUT[$j]=${eVarLine[$i]} ((j++)) done eIsFind=0 # not finde yet # echo eVarIN ${#eVarIN[@]}: ${eVarIN[@]} ; echo eVarOUT ${#eVarOUT[@]}: ${eVarOUT[@]} ################################################################################### else if [[ "${Line:0:${#eEND}}" == "${eEND}" ]] # check for end of sentence then # echo "END: $Line" #echo "Line: ${Line:0:${#eEND}} == " # eISVAR=1 # source $eTmpFile #. data-file # execute file and set values for vars # > $eTmpFile # erase temporary file for setap vars continue # while read Line fi # #Check for error message and error vars set # if [[ "${Line:0:${#eERROR}}" == "${eERROR}" ]] # check for ERROR of sentence then # echo "<ERROR>:${eIsFind} $Line" #echo "Line: ${Line:0:${#eEND}} == " LineErr="" if [[ "eIsFind" -eq "0" ]] then ((CheckTabelErrors++)) LineErr="${Line#${eERROR}}" #remove <Error> echo "!!! ERROR CheckTabel.sh LineErr: ${eCurLine}" #;echo "Line: ${Line}" ErrVarOut="${LineErr#*${eInOutDevisor}}" #+ ${#eInOutDevisor}+ LineErr="${LineErr%${eInOutDevisor}*}" eDataOUT=( `echo "$ErrVarOut"` ) ( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done echo "${LineErr}" # error command ) >> $eTmpFile # create temporary file for setup vars and show error message fi # ---------- execute -------------- eISVAR=1 # its mean , that next line will with varnames source $eTmpFile #. data-file # execute file and set values for vars > $eTmpFile # erase temporary file for setap vars continue # while read Line fi #for skeep all next currient tabel parametrs if [[ "eIsFind" -eq "1" ]] then continue # while read Line fi eDatLine=( `echo "$Line"` ) # echo OUT ${#eDatLine[@]} ${eDatLine[@]} cntOut=${#eDatLine[@]} if (( $cntIn != $cntOut )) then echo !!! Error CheckTabel.sh in Conditions line=${eCurLine} formating Vars $cntIn but Data $cntOut, count of parametrs not equel ! ;echo !!! ${eVarIN[@]} === ${eDatLine[@]} continue # while read Line fi # # main check for compare tabale value and var value in currient string # ((cmpCnt=0)) for (( i = 0 ; i < cntOut ; i++ )) do #get input data if [ "${eDatLine[${i}]}" == "${eInOutDevisor}" ] ; then ((outBgn=i + 1)) break fi # echo DEBUG Element [$i]: ${eDatLine[$i]} val=${!eDatLine[$i]} eDatLine=${eDatLine[${i}]} == eVarDatIN="${eVarDatIN[$i]}" if [ "${eDatLine[${i}]}" == "${eVarDatIN[$i]}" ] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eANY}" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eNOTEMPTY}" && "${eVarDatIN[$i]}" != "" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eEMPTY}" && "${eVarDatIN[$i]}" == "" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi done # echo DEBUG "$cmpCnt" == "(($outBgn - 1 ))" outBgn=$outBgn cntIn=$cntIn if (( "$cmpCnt" == "(($outBgn - 1 ))" )) # there are data in this string #${#eVarIN[@]} then (( j = 0 )) for (( i = $outBgn ; i < cntOut ; i++ )) do # get value for output vars eDataOUT[$j]=${eDatLine[$i]} # echo "DEBUG ${eVarOUT[$j]}=${eDataOUT[$j]}" ((j++)) done ( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done ) >> $eTmpFile # create temporary file for setap vars eIsFind=1 # echo OK: ${eVarIN[@]} == ${eDataIN[@]} '=>' ${eVarOUT[@]} == ${eDataOUT[@]} fi fi else #skeep empty and commets lines # echo Comment: $Line eDeb="" # for skeep warning fi done #while read Line ######################################################################3 IFS=$OLD_IFS #rm $eTmpFile
.
.
, – ? , , .
, , .
( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done echo "${LineErr}" # error command ) >> $eTmpFile # create temporary file for setup vars and show error message
. , .
# ---------- execute -------------- eISVAR=1 # its mean , that next line will with varnames source $eTmpFile #. data-file # execute file and set values for vars > $eTmpFile # erase temporary file for setup vars
tmpSetVar.sh , Result="OK"
Result="OK"
ToDo=""
Speed=""
ToDo="$ToDo"
Speed="$Speed"
echo "Wrong ramp police";
ToDo="$ToDo"
Speed="$Speed"
echo "Wrong let have road";
ToDoAlter=""
SpeedAlter=""
. – .
, .
Perl - , .
.
CheckTabel.sh #/bin/ksh #/bin/bash # # script CheckTabel.sh - check tabel data # # See on : http://www.linuxcookbook.ru/books/absguide/ch09s05.html # #12.02.2013 _aap_ created by Patratskiy Aleksey #26.02.2013 _aap_ RELAEASE work with errors, get first right parametrs #28.02.2013 _aap_ fix same problem var counts #05.03.2013 _aap_ can use without <END> # #Limits : #Comment '#' work only for first position in string #Devior TAB If parameters use TAB it can not be used #input data: Conditions # # after you can check variable "CheckTabelErrors" for errors count #exaple of var :Conditions #Conditions=' ##check stuff of vars and data #Check var parametrs #varIn1 varIn2 varIn3 varIn4 => varOut1 varOut2 #varIn1varIn1 varIn2varIn2 varIn3varIn3 varIn4varIn4 => AAPvarOut1varOut1 AAPvarOut2varOut2 #<.> <_> <> dsf => sdf sdf #<ERROR> Error `exit 1` => <> <> #<END> #' #internals Vars: eTmpFile=$HOME/tmp/tmpSetVar.sh eDIVISOR=' ' eInOutDevisor='=>' eEND='<END>' eERROR='<ERROR>' eANY='<?>' eEMPTY='<_>' eNOTEMPTY='<.>' eISVAR=1 eDeb="" eIsFind=0 ((CheckTabelErrors=0)) ((eCurLine=0)) #for ksh typeset -A eDataIN typeset -A eDataOUT typeset -A eVarIN typeset -A eVarDatIN typeset -A eVarOUT typeset -A eVarLine typeset -A eDatLine #for bash #typeset -a eDataIN #typeset -a eDataOUT #typeset -a eVarIN #typeset -a eVarDatIN #typeset -a eVarOUT #typeset -a eVarLine #typeset -a eDatLine #source $eTmpFile # erase temporary file for setap vars > $eTmpFile # erase temporary file for setap vars #echo ifs=$IFS OLD_IFS="$IFS" IFS=$' '# echo "${Conditions}" | while read Line do ((eCurLine++)) # echo "LineErr: ${eCurLine}" ;echo "Line: ${Line}" if [[ "${Line:0:1}" != "#" && "$Line" != "" && "${Line:0:${#eEND}}" != "${eEND}" ]] #skeep empty and commets lines AND with <END> then if [[ "eISVAR" -eq "1" ]] # check for var names line then eISVAR=0 eVarLine=(`echo "$Line"`) cntIn=${#eVarLine[@]} # echo ${#eVarLine[@]} ${eVarLine[@]} for (( i = 0 ; i < cntIn ; i++ )) do #get names of input vars if [ "${eVarLine[${i}]}" == "${eInOutDevisor}" ] then ((outBgn=i + 1)) break fi eVarIN[${i}]=${eVarLine[$i]} tmp=${eVarLine[$i]} # get name of input var eval tmp=\$$tmp # gat var value by var name eVarDatIN[${i}]=${tmp} # echo DEBUG Element [$i]: ${eVarLine[$i]} val=${eVarIN[${i}]} eVarDatIN=${eVarDatIN[${i}]} done # echo DEBUG outBgn=$outBgn cntIn=$cntIn if (( cntIn == 0 || outBgn == 0 )) then echo !!! Error CheckTabel.sh formating outBgn=$outBgn cntIn=$cntIn wrong eDIVISOR TAB continue fi (( j = 0 )) for (( i = $outBgn ; i < cntIn ; i++ )) do # get name of output vars # echo "${eVarLine[$i]}=Set${i}" eVarOUT[$j]=${eVarLine[$i]} ((j++)) done eIsFind=0 # not finde yet # echo eVarIN ${#eVarIN[@]}: ${eVarIN[@]} ; echo eVarOUT ${#eVarOUT[@]}: ${eVarOUT[@]} ################################################################################### else if [[ "${Line:0:${#eEND}}" == "${eEND}" ]] # check for end of sentence then # echo "END: $Line" #echo "Line: ${Line:0:${#eEND}} == " # eISVAR=1 # source $eTmpFile #. data-file # execute file and set values for vars # > $eTmpFile # erase temporary file for setap vars continue # while read Line fi # #Check for error message and error vars set # if [[ "${Line:0:${#eERROR}}" == "${eERROR}" ]] # check for ERROR of sentence then # echo "<ERROR>:${eIsFind} $Line" #echo "Line: ${Line:0:${#eEND}} == " LineErr="" if [[ "eIsFind" -eq "0" ]] then ((CheckTabelErrors++)) LineErr="${Line#${eERROR}}" #remove <Error> echo "!!! ERROR CheckTabel.sh LineErr: ${eCurLine}" #;echo "Line: ${Line}" ErrVarOut="${LineErr#*${eInOutDevisor}}" #+ ${#eInOutDevisor}+ LineErr="${LineErr%${eInOutDevisor}*}" eDataOUT=( `echo "$ErrVarOut"` ) ( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done echo "${LineErr}" # error command ) >> $eTmpFile # create temporary file for setup vars and show error message fi # ---------- execute -------------- eISVAR=1 # its mean , that next line will with varnames source $eTmpFile #. data-file # execute file and set values for vars > $eTmpFile # erase temporary file for setap vars continue # while read Line fi #for skeep all next currient tabel parametrs if [[ "eIsFind" -eq "1" ]] then continue # while read Line fi eDatLine=( `echo "$Line"` ) # echo OUT ${#eDatLine[@]} ${eDatLine[@]} cntOut=${#eDatLine[@]} if (( $cntIn != $cntOut )) then echo !!! Error CheckTabel.sh in Conditions line=${eCurLine} formating Vars $cntIn but Data $cntOut, count of parametrs not equel ! ;echo !!! ${eVarIN[@]} === ${eDatLine[@]} continue # while read Line fi # # main check for compare tabale value and var value in currient string # ((cmpCnt=0)) for (( i = 0 ; i < cntOut ; i++ )) do #get input data if [ "${eDatLine[${i}]}" == "${eInOutDevisor}" ] ; then ((outBgn=i + 1)) break fi # echo DEBUG Element [$i]: ${eDatLine[$i]} val=${!eDatLine[$i]} eDatLine=${eDatLine[${i}]} == eVarDatIN="${eVarDatIN[$i]}" if [ "${eDatLine[${i}]}" == "${eVarDatIN[$i]}" ] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eANY}" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eNOTEMPTY}" && "${eVarDatIN[$i]}" != "" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eEMPTY}" && "${eVarDatIN[$i]}" == "" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi done # echo DEBUG "$cmpCnt" == "(($outBgn - 1 ))" outBgn=$outBgn cntIn=$cntIn if (( "$cmpCnt" == "(($outBgn - 1 ))" )) # there are data in this string #${#eVarIN[@]} then (( j = 0 )) for (( i = $outBgn ; i < cntOut ; i++ )) do # get value for output vars eDataOUT[$j]=${eDatLine[$i]} # echo "DEBUG ${eVarOUT[$j]}=${eDataOUT[$j]}" ((j++)) done ( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done ) >> $eTmpFile # create temporary file for setap vars eIsFind=1 # echo OK: ${eVarIN[@]} == ${eDataIN[@]} '=>' ${eVarOUT[@]} == ${eDataOUT[@]} fi fi else #skeep empty and commets lines # echo Comment: $Line eDeb="" # for skeep warning fi done #while read Line ######################################################################3 IFS=$OLD_IFS #rm $eTmpFile
.
.
, – ? , , .
, , .
( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done echo "${LineErr}" # error command ) >> $eTmpFile # create temporary file for setup vars and show error message
. , .
# ---------- execute -------------- eISVAR=1 # its mean , that next line will with varnames source $eTmpFile #. data-file # execute file and set values for vars > $eTmpFile # erase temporary file for setup vars
tmpSetVar.sh , Result="OK"
Result="OK"
ToDo=""
Speed=""
ToDo="$ToDo"
Speed="$Speed"
echo "Wrong ramp police";
ToDo="$ToDo"
Speed="$Speed"
echo "Wrong let have road";
ToDoAlter=""
SpeedAlter=""
. – .
, .
Perl - , .
.
CheckTabel.sh #/bin/ksh #/bin/bash # # script CheckTabel.sh - check tabel data # # See on : http://www.linuxcookbook.ru/books/absguide/ch09s05.html # #12.02.2013 _aap_ created by Patratskiy Aleksey #26.02.2013 _aap_ RELAEASE work with errors, get first right parametrs #28.02.2013 _aap_ fix same problem var counts #05.03.2013 _aap_ can use without <END> # #Limits : #Comment '#' work only for first position in string #Devior TAB If parameters use TAB it can not be used #input data: Conditions # # after you can check variable "CheckTabelErrors" for errors count #exaple of var :Conditions #Conditions=' ##check stuff of vars and data #Check var parametrs #varIn1 varIn2 varIn3 varIn4 => varOut1 varOut2 #varIn1varIn1 varIn2varIn2 varIn3varIn3 varIn4varIn4 => AAPvarOut1varOut1 AAPvarOut2varOut2 #<.> <_> <> dsf => sdf sdf #<ERROR> Error `exit 1` => <> <> #<END> #' #internals Vars: eTmpFile=$HOME/tmp/tmpSetVar.sh eDIVISOR=' ' eInOutDevisor='=>' eEND='<END>' eERROR='<ERROR>' eANY='<?>' eEMPTY='<_>' eNOTEMPTY='<.>' eISVAR=1 eDeb="" eIsFind=0 ((CheckTabelErrors=0)) ((eCurLine=0)) #for ksh typeset -A eDataIN typeset -A eDataOUT typeset -A eVarIN typeset -A eVarDatIN typeset -A eVarOUT typeset -A eVarLine typeset -A eDatLine #for bash #typeset -a eDataIN #typeset -a eDataOUT #typeset -a eVarIN #typeset -a eVarDatIN #typeset -a eVarOUT #typeset -a eVarLine #typeset -a eDatLine #source $eTmpFile # erase temporary file for setap vars > $eTmpFile # erase temporary file for setap vars #echo ifs=$IFS OLD_IFS="$IFS" IFS=$' '# echo "${Conditions}" | while read Line do ((eCurLine++)) # echo "LineErr: ${eCurLine}" ;echo "Line: ${Line}" if [[ "${Line:0:1}" != "#" && "$Line" != "" && "${Line:0:${#eEND}}" != "${eEND}" ]] #skeep empty and commets lines AND with <END> then if [[ "eISVAR" -eq "1" ]] # check for var names line then eISVAR=0 eVarLine=(`echo "$Line"`) cntIn=${#eVarLine[@]} # echo ${#eVarLine[@]} ${eVarLine[@]} for (( i = 0 ; i < cntIn ; i++ )) do #get names of input vars if [ "${eVarLine[${i}]}" == "${eInOutDevisor}" ] then ((outBgn=i + 1)) break fi eVarIN[${i}]=${eVarLine[$i]} tmp=${eVarLine[$i]} # get name of input var eval tmp=\$$tmp # gat var value by var name eVarDatIN[${i}]=${tmp} # echo DEBUG Element [$i]: ${eVarLine[$i]} val=${eVarIN[${i}]} eVarDatIN=${eVarDatIN[${i}]} done # echo DEBUG outBgn=$outBgn cntIn=$cntIn if (( cntIn == 0 || outBgn == 0 )) then echo !!! Error CheckTabel.sh formating outBgn=$outBgn cntIn=$cntIn wrong eDIVISOR TAB continue fi (( j = 0 )) for (( i = $outBgn ; i < cntIn ; i++ )) do # get name of output vars # echo "${eVarLine[$i]}=Set${i}" eVarOUT[$j]=${eVarLine[$i]} ((j++)) done eIsFind=0 # not finde yet # echo eVarIN ${#eVarIN[@]}: ${eVarIN[@]} ; echo eVarOUT ${#eVarOUT[@]}: ${eVarOUT[@]} ################################################################################### else if [[ "${Line:0:${#eEND}}" == "${eEND}" ]] # check for end of sentence then # echo "END: $Line" #echo "Line: ${Line:0:${#eEND}} == " # eISVAR=1 # source $eTmpFile #. data-file # execute file and set values for vars # > $eTmpFile # erase temporary file for setap vars continue # while read Line fi # #Check for error message and error vars set # if [[ "${Line:0:${#eERROR}}" == "${eERROR}" ]] # check for ERROR of sentence then # echo "<ERROR>:${eIsFind} $Line" #echo "Line: ${Line:0:${#eEND}} == " LineErr="" if [[ "eIsFind" -eq "0" ]] then ((CheckTabelErrors++)) LineErr="${Line#${eERROR}}" #remove <Error> echo "!!! ERROR CheckTabel.sh LineErr: ${eCurLine}" #;echo "Line: ${Line}" ErrVarOut="${LineErr#*${eInOutDevisor}}" #+ ${#eInOutDevisor}+ LineErr="${LineErr%${eInOutDevisor}*}" eDataOUT=( `echo "$ErrVarOut"` ) ( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done echo "${LineErr}" # error command ) >> $eTmpFile # create temporary file for setup vars and show error message fi # ---------- execute -------------- eISVAR=1 # its mean , that next line will with varnames source $eTmpFile #. data-file # execute file and set values for vars > $eTmpFile # erase temporary file for setap vars continue # while read Line fi #for skeep all next currient tabel parametrs if [[ "eIsFind" -eq "1" ]] then continue # while read Line fi eDatLine=( `echo "$Line"` ) # echo OUT ${#eDatLine[@]} ${eDatLine[@]} cntOut=${#eDatLine[@]} if (( $cntIn != $cntOut )) then echo !!! Error CheckTabel.sh in Conditions line=${eCurLine} formating Vars $cntIn but Data $cntOut, count of parametrs not equel ! ;echo !!! ${eVarIN[@]} === ${eDatLine[@]} continue # while read Line fi # # main check for compare tabale value and var value in currient string # ((cmpCnt=0)) for (( i = 0 ; i < cntOut ; i++ )) do #get input data if [ "${eDatLine[${i}]}" == "${eInOutDevisor}" ] ; then ((outBgn=i + 1)) break fi # echo DEBUG Element [$i]: ${eDatLine[$i]} val=${!eDatLine[$i]} eDatLine=${eDatLine[${i}]} == eVarDatIN="${eVarDatIN[$i]}" if [ "${eDatLine[${i}]}" == "${eVarDatIN[$i]}" ] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eANY}" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eNOTEMPTY}" && "${eVarDatIN[$i]}" != "" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eEMPTY}" && "${eVarDatIN[$i]}" == "" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi done # echo DEBUG "$cmpCnt" == "(($outBgn - 1 ))" outBgn=$outBgn cntIn=$cntIn if (( "$cmpCnt" == "(($outBgn - 1 ))" )) # there are data in this string #${#eVarIN[@]} then (( j = 0 )) for (( i = $outBgn ; i < cntOut ; i++ )) do # get value for output vars eDataOUT[$j]=${eDatLine[$i]} # echo "DEBUG ${eVarOUT[$j]}=${eDataOUT[$j]}" ((j++)) done ( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done ) >> $eTmpFile # create temporary file for setap vars eIsFind=1 # echo OK: ${eVarIN[@]} == ${eDataIN[@]} '=>' ${eVarOUT[@]} == ${eDataOUT[@]} fi fi else #skeep empty and commets lines # echo Comment: $Line eDeb="" # for skeep warning fi done #while read Line ######################################################################3 IFS=$OLD_IFS #rm $eTmpFile
.
.
, – ? , , .
, , .
( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done echo "${LineErr}" # error command ) >> $eTmpFile # create temporary file for setup vars and show error message
. , .
# ---------- execute -------------- eISVAR=1 # its mean , that next line will with varnames source $eTmpFile #. data-file # execute file and set values for vars > $eTmpFile # erase temporary file for setup vars
tmpSetVar.sh , Result="OK"
Result="OK"
ToDo=""
Speed=""
ToDo="$ToDo"
Speed="$Speed"
echo "Wrong ramp police";
ToDo="$ToDo"
Speed="$Speed"
echo "Wrong let have road";
ToDoAlter=""
SpeedAlter=""
. – .
, .
Perl - , .
.
CheckTabel.sh #/bin/ksh #/bin/bash # # script CheckTabel.sh - check tabel data # # See on : http://www.linuxcookbook.ru/books/absguide/ch09s05.html # #12.02.2013 _aap_ created by Patratskiy Aleksey #26.02.2013 _aap_ RELAEASE work with errors, get first right parametrs #28.02.2013 _aap_ fix same problem var counts #05.03.2013 _aap_ can use without <END> # #Limits : #Comment '#' work only for first position in string #Devior TAB If parameters use TAB it can not be used #input data: Conditions # # after you can check variable "CheckTabelErrors" for errors count #exaple of var :Conditions #Conditions=' ##check stuff of vars and data #Check var parametrs #varIn1 varIn2 varIn3 varIn4 => varOut1 varOut2 #varIn1varIn1 varIn2varIn2 varIn3varIn3 varIn4varIn4 => AAPvarOut1varOut1 AAPvarOut2varOut2 #<.> <_> <> dsf => sdf sdf #<ERROR> Error `exit 1` => <> <> #<END> #' #internals Vars: eTmpFile=$HOME/tmp/tmpSetVar.sh eDIVISOR=' ' eInOutDevisor='=>' eEND='<END>' eERROR='<ERROR>' eANY='<?>' eEMPTY='<_>' eNOTEMPTY='<.>' eISVAR=1 eDeb="" eIsFind=0 ((CheckTabelErrors=0)) ((eCurLine=0)) #for ksh typeset -A eDataIN typeset -A eDataOUT typeset -A eVarIN typeset -A eVarDatIN typeset -A eVarOUT typeset -A eVarLine typeset -A eDatLine #for bash #typeset -a eDataIN #typeset -a eDataOUT #typeset -a eVarIN #typeset -a eVarDatIN #typeset -a eVarOUT #typeset -a eVarLine #typeset -a eDatLine #source $eTmpFile # erase temporary file for setap vars > $eTmpFile # erase temporary file for setap vars #echo ifs=$IFS OLD_IFS="$IFS" IFS=$' '# echo "${Conditions}" | while read Line do ((eCurLine++)) # echo "LineErr: ${eCurLine}" ;echo "Line: ${Line}" if [[ "${Line:0:1}" != "#" && "$Line" != "" && "${Line:0:${#eEND}}" != "${eEND}" ]] #skeep empty and commets lines AND with <END> then if [[ "eISVAR" -eq "1" ]] # check for var names line then eISVAR=0 eVarLine=(`echo "$Line"`) cntIn=${#eVarLine[@]} # echo ${#eVarLine[@]} ${eVarLine[@]} for (( i = 0 ; i < cntIn ; i++ )) do #get names of input vars if [ "${eVarLine[${i}]}" == "${eInOutDevisor}" ] then ((outBgn=i + 1)) break fi eVarIN[${i}]=${eVarLine[$i]} tmp=${eVarLine[$i]} # get name of input var eval tmp=\$$tmp # gat var value by var name eVarDatIN[${i}]=${tmp} # echo DEBUG Element [$i]: ${eVarLine[$i]} val=${eVarIN[${i}]} eVarDatIN=${eVarDatIN[${i}]} done # echo DEBUG outBgn=$outBgn cntIn=$cntIn if (( cntIn == 0 || outBgn == 0 )) then echo !!! Error CheckTabel.sh formating outBgn=$outBgn cntIn=$cntIn wrong eDIVISOR TAB continue fi (( j = 0 )) for (( i = $outBgn ; i < cntIn ; i++ )) do # get name of output vars # echo "${eVarLine[$i]}=Set${i}" eVarOUT[$j]=${eVarLine[$i]} ((j++)) done eIsFind=0 # not finde yet # echo eVarIN ${#eVarIN[@]}: ${eVarIN[@]} ; echo eVarOUT ${#eVarOUT[@]}: ${eVarOUT[@]} ################################################################################### else if [[ "${Line:0:${#eEND}}" == "${eEND}" ]] # check for end of sentence then # echo "END: $Line" #echo "Line: ${Line:0:${#eEND}} == " # eISVAR=1 # source $eTmpFile #. data-file # execute file and set values for vars # > $eTmpFile # erase temporary file for setap vars continue # while read Line fi # #Check for error message and error vars set # if [[ "${Line:0:${#eERROR}}" == "${eERROR}" ]] # check for ERROR of sentence then # echo "<ERROR>:${eIsFind} $Line" #echo "Line: ${Line:0:${#eEND}} == " LineErr="" if [[ "eIsFind" -eq "0" ]] then ((CheckTabelErrors++)) LineErr="${Line#${eERROR}}" #remove <Error> echo "!!! ERROR CheckTabel.sh LineErr: ${eCurLine}" #;echo "Line: ${Line}" ErrVarOut="${LineErr#*${eInOutDevisor}}" #+ ${#eInOutDevisor}+ LineErr="${LineErr%${eInOutDevisor}*}" eDataOUT=( `echo "$ErrVarOut"` ) ( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done echo "${LineErr}" # error command ) >> $eTmpFile # create temporary file for setup vars and show error message fi # ---------- execute -------------- eISVAR=1 # its mean , that next line will with varnames source $eTmpFile #. data-file # execute file and set values for vars > $eTmpFile # erase temporary file for setap vars continue # while read Line fi #for skeep all next currient tabel parametrs if [[ "eIsFind" -eq "1" ]] then continue # while read Line fi eDatLine=( `echo "$Line"` ) # echo OUT ${#eDatLine[@]} ${eDatLine[@]} cntOut=${#eDatLine[@]} if (( $cntIn != $cntOut )) then echo !!! Error CheckTabel.sh in Conditions line=${eCurLine} formating Vars $cntIn but Data $cntOut, count of parametrs not equel ! ;echo !!! ${eVarIN[@]} === ${eDatLine[@]} continue # while read Line fi # # main check for compare tabale value and var value in currient string # ((cmpCnt=0)) for (( i = 0 ; i < cntOut ; i++ )) do #get input data if [ "${eDatLine[${i}]}" == "${eInOutDevisor}" ] ; then ((outBgn=i + 1)) break fi # echo DEBUG Element [$i]: ${eDatLine[$i]} val=${!eDatLine[$i]} eDatLine=${eDatLine[${i}]} == eVarDatIN="${eVarDatIN[$i]}" if [ "${eDatLine[${i}]}" == "${eVarDatIN[$i]}" ] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eANY}" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eNOTEMPTY}" && "${eVarDatIN[$i]}" != "" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eEMPTY}" && "${eVarDatIN[$i]}" == "" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi done # echo DEBUG "$cmpCnt" == "(($outBgn - 1 ))" outBgn=$outBgn cntIn=$cntIn if (( "$cmpCnt" == "(($outBgn - 1 ))" )) # there are data in this string #${#eVarIN[@]} then (( j = 0 )) for (( i = $outBgn ; i < cntOut ; i++ )) do # get value for output vars eDataOUT[$j]=${eDatLine[$i]} # echo "DEBUG ${eVarOUT[$j]}=${eDataOUT[$j]}" ((j++)) done ( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done ) >> $eTmpFile # create temporary file for setap vars eIsFind=1 # echo OK: ${eVarIN[@]} == ${eDataIN[@]} '=>' ${eVarOUT[@]} == ${eDataOUT[@]} fi fi else #skeep empty and commets lines # echo Comment: $Line eDeb="" # for skeep warning fi done #while read Line ######################################################################3 IFS=$OLD_IFS #rm $eTmpFile
.
.
, – ? , , .
, , .
( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done echo "${LineErr}" # error command ) >> $eTmpFile # create temporary file for setup vars and show error message
. , .
# ---------- execute -------------- eISVAR=1 # its mean , that next line will with varnames source $eTmpFile #. data-file # execute file and set values for vars > $eTmpFile # erase temporary file for setup vars
tmpSetVar.sh , Result="OK"
Result="OK"
ToDo=""
Speed=""
ToDo="$ToDo"
Speed="$Speed"
echo "Wrong ramp police";
ToDo="$ToDo"
Speed="$Speed"
echo "Wrong let have road";
ToDoAlter=""
SpeedAlter=""
. – .
, .
Perl - , .
.
CheckTabel.sh #/bin/ksh #/bin/bash # # script CheckTabel.sh - check tabel data # # See on : http://www.linuxcookbook.ru/books/absguide/ch09s05.html # #12.02.2013 _aap_ created by Patratskiy Aleksey #26.02.2013 _aap_ RELAEASE work with errors, get first right parametrs #28.02.2013 _aap_ fix same problem var counts #05.03.2013 _aap_ can use without <END> # #Limits : #Comment '#' work only for first position in string #Devior TAB If parameters use TAB it can not be used #input data: Conditions # # after you can check variable "CheckTabelErrors" for errors count #exaple of var :Conditions #Conditions=' ##check stuff of vars and data #Check var parametrs #varIn1 varIn2 varIn3 varIn4 => varOut1 varOut2 #varIn1varIn1 varIn2varIn2 varIn3varIn3 varIn4varIn4 => AAPvarOut1varOut1 AAPvarOut2varOut2 #<.> <_> <> dsf => sdf sdf #<ERROR> Error `exit 1` => <> <> #<END> #' #internals Vars: eTmpFile=$HOME/tmp/tmpSetVar.sh eDIVISOR=' ' eInOutDevisor='=>' eEND='<END>' eERROR='<ERROR>' eANY='<?>' eEMPTY='<_>' eNOTEMPTY='<.>' eISVAR=1 eDeb="" eIsFind=0 ((CheckTabelErrors=0)) ((eCurLine=0)) #for ksh typeset -A eDataIN typeset -A eDataOUT typeset -A eVarIN typeset -A eVarDatIN typeset -A eVarOUT typeset -A eVarLine typeset -A eDatLine #for bash #typeset -a eDataIN #typeset -a eDataOUT #typeset -a eVarIN #typeset -a eVarDatIN #typeset -a eVarOUT #typeset -a eVarLine #typeset -a eDatLine #source $eTmpFile # erase temporary file for setap vars > $eTmpFile # erase temporary file for setap vars #echo ifs=$IFS OLD_IFS="$IFS" IFS=$' '# echo "${Conditions}" | while read Line do ((eCurLine++)) # echo "LineErr: ${eCurLine}" ;echo "Line: ${Line}" if [[ "${Line:0:1}" != "#" && "$Line" != "" && "${Line:0:${#eEND}}" != "${eEND}" ]] #skeep empty and commets lines AND with <END> then if [[ "eISVAR" -eq "1" ]] # check for var names line then eISVAR=0 eVarLine=(`echo "$Line"`) cntIn=${#eVarLine[@]} # echo ${#eVarLine[@]} ${eVarLine[@]} for (( i = 0 ; i < cntIn ; i++ )) do #get names of input vars if [ "${eVarLine[${i}]}" == "${eInOutDevisor}" ] then ((outBgn=i + 1)) break fi eVarIN[${i}]=${eVarLine[$i]} tmp=${eVarLine[$i]} # get name of input var eval tmp=\$$tmp # gat var value by var name eVarDatIN[${i}]=${tmp} # echo DEBUG Element [$i]: ${eVarLine[$i]} val=${eVarIN[${i}]} eVarDatIN=${eVarDatIN[${i}]} done # echo DEBUG outBgn=$outBgn cntIn=$cntIn if (( cntIn == 0 || outBgn == 0 )) then echo !!! Error CheckTabel.sh formating outBgn=$outBgn cntIn=$cntIn wrong eDIVISOR TAB continue fi (( j = 0 )) for (( i = $outBgn ; i < cntIn ; i++ )) do # get name of output vars # echo "${eVarLine[$i]}=Set${i}" eVarOUT[$j]=${eVarLine[$i]} ((j++)) done eIsFind=0 # not finde yet # echo eVarIN ${#eVarIN[@]}: ${eVarIN[@]} ; echo eVarOUT ${#eVarOUT[@]}: ${eVarOUT[@]} ################################################################################### else if [[ "${Line:0:${#eEND}}" == "${eEND}" ]] # check for end of sentence then # echo "END: $Line" #echo "Line: ${Line:0:${#eEND}} == " # eISVAR=1 # source $eTmpFile #. data-file # execute file and set values for vars # > $eTmpFile # erase temporary file for setap vars continue # while read Line fi # #Check for error message and error vars set # if [[ "${Line:0:${#eERROR}}" == "${eERROR}" ]] # check for ERROR of sentence then # echo "<ERROR>:${eIsFind} $Line" #echo "Line: ${Line:0:${#eEND}} == " LineErr="" if [[ "eIsFind" -eq "0" ]] then ((CheckTabelErrors++)) LineErr="${Line#${eERROR}}" #remove <Error> echo "!!! ERROR CheckTabel.sh LineErr: ${eCurLine}" #;echo "Line: ${Line}" ErrVarOut="${LineErr#*${eInOutDevisor}}" #+ ${#eInOutDevisor}+ LineErr="${LineErr%${eInOutDevisor}*}" eDataOUT=( `echo "$ErrVarOut"` ) ( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done echo "${LineErr}" # error command ) >> $eTmpFile # create temporary file for setup vars and show error message fi # ---------- execute -------------- eISVAR=1 # its mean , that next line will with varnames source $eTmpFile #. data-file # execute file and set values for vars > $eTmpFile # erase temporary file for setap vars continue # while read Line fi #for skeep all next currient tabel parametrs if [[ "eIsFind" -eq "1" ]] then continue # while read Line fi eDatLine=( `echo "$Line"` ) # echo OUT ${#eDatLine[@]} ${eDatLine[@]} cntOut=${#eDatLine[@]} if (( $cntIn != $cntOut )) then echo !!! Error CheckTabel.sh in Conditions line=${eCurLine} formating Vars $cntIn but Data $cntOut, count of parametrs not equel ! ;echo !!! ${eVarIN[@]} === ${eDatLine[@]} continue # while read Line fi # # main check for compare tabale value and var value in currient string # ((cmpCnt=0)) for (( i = 0 ; i < cntOut ; i++ )) do #get input data if [ "${eDatLine[${i}]}" == "${eInOutDevisor}" ] ; then ((outBgn=i + 1)) break fi # echo DEBUG Element [$i]: ${eDatLine[$i]} val=${!eDatLine[$i]} eDatLine=${eDatLine[${i}]} == eVarDatIN="${eVarDatIN[$i]}" if [ "${eDatLine[${i}]}" == "${eVarDatIN[$i]}" ] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eANY}" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eNOTEMPTY}" && "${eVarDatIN[$i]}" != "" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eEMPTY}" && "${eVarDatIN[$i]}" == "" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi done # echo DEBUG "$cmpCnt" == "(($outBgn - 1 ))" outBgn=$outBgn cntIn=$cntIn if (( "$cmpCnt" == "(($outBgn - 1 ))" )) # there are data in this string #${#eVarIN[@]} then (( j = 0 )) for (( i = $outBgn ; i < cntOut ; i++ )) do # get value for output vars eDataOUT[$j]=${eDatLine[$i]} # echo "DEBUG ${eVarOUT[$j]}=${eDataOUT[$j]}" ((j++)) done ( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done ) >> $eTmpFile # create temporary file for setap vars eIsFind=1 # echo OK: ${eVarIN[@]} == ${eDataIN[@]} '=>' ${eVarOUT[@]} == ${eDataOUT[@]} fi fi else #skeep empty and commets lines # echo Comment: $Line eDeb="" # for skeep warning fi done #while read Line ######################################################################3 IFS=$OLD_IFS #rm $eTmpFile
.
.
, – ? , , .
, , .
( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done echo "${LineErr}" # error command ) >> $eTmpFile # create temporary file for setup vars and show error message
. , .
# ---------- execute -------------- eISVAR=1 # its mean , that next line will with varnames source $eTmpFile #. data-file # execute file and set values for vars > $eTmpFile # erase temporary file for setup vars
tmpSetVar.sh , Result="OK"
Result="OK"
ToDo=""
Speed=""
ToDo="$ToDo"
Speed="$Speed"
echo "Wrong ramp police";
ToDo="$ToDo"
Speed="$Speed"
echo "Wrong let have road";
ToDoAlter=""
SpeedAlter=""
. – .
, .
Perl - , .
.
CheckTabel.sh #/bin/ksh #/bin/bash # # script CheckTabel.sh - check tabel data # # See on : http://www.linuxcookbook.ru/books/absguide/ch09s05.html # #12.02.2013 _aap_ created by Patratskiy Aleksey #26.02.2013 _aap_ RELAEASE work with errors, get first right parametrs #28.02.2013 _aap_ fix same problem var counts #05.03.2013 _aap_ can use without <END> # #Limits : #Comment '#' work only for first position in string #Devior TAB If parameters use TAB it can not be used #input data: Conditions # # after you can check variable "CheckTabelErrors" for errors count #exaple of var :Conditions #Conditions=' ##check stuff of vars and data #Check var parametrs #varIn1 varIn2 varIn3 varIn4 => varOut1 varOut2 #varIn1varIn1 varIn2varIn2 varIn3varIn3 varIn4varIn4 => AAPvarOut1varOut1 AAPvarOut2varOut2 #<.> <_> <> dsf => sdf sdf #<ERROR> Error `exit 1` => <> <> #<END> #' #internals Vars: eTmpFile=$HOME/tmp/tmpSetVar.sh eDIVISOR=' ' eInOutDevisor='=>' eEND='<END>' eERROR='<ERROR>' eANY='<?>' eEMPTY='<_>' eNOTEMPTY='<.>' eISVAR=1 eDeb="" eIsFind=0 ((CheckTabelErrors=0)) ((eCurLine=0)) #for ksh typeset -A eDataIN typeset -A eDataOUT typeset -A eVarIN typeset -A eVarDatIN typeset -A eVarOUT typeset -A eVarLine typeset -A eDatLine #for bash #typeset -a eDataIN #typeset -a eDataOUT #typeset -a eVarIN #typeset -a eVarDatIN #typeset -a eVarOUT #typeset -a eVarLine #typeset -a eDatLine #source $eTmpFile # erase temporary file for setap vars > $eTmpFile # erase temporary file for setap vars #echo ifs=$IFS OLD_IFS="$IFS" IFS=$' '# echo "${Conditions}" | while read Line do ((eCurLine++)) # echo "LineErr: ${eCurLine}" ;echo "Line: ${Line}" if [[ "${Line:0:1}" != "#" && "$Line" != "" && "${Line:0:${#eEND}}" != "${eEND}" ]] #skeep empty and commets lines AND with <END> then if [[ "eISVAR" -eq "1" ]] # check for var names line then eISVAR=0 eVarLine=(`echo "$Line"`) cntIn=${#eVarLine[@]} # echo ${#eVarLine[@]} ${eVarLine[@]} for (( i = 0 ; i < cntIn ; i++ )) do #get names of input vars if [ "${eVarLine[${i}]}" == "${eInOutDevisor}" ] then ((outBgn=i + 1)) break fi eVarIN[${i}]=${eVarLine[$i]} tmp=${eVarLine[$i]} # get name of input var eval tmp=\$$tmp # gat var value by var name eVarDatIN[${i}]=${tmp} # echo DEBUG Element [$i]: ${eVarLine[$i]} val=${eVarIN[${i}]} eVarDatIN=${eVarDatIN[${i}]} done # echo DEBUG outBgn=$outBgn cntIn=$cntIn if (( cntIn == 0 || outBgn == 0 )) then echo !!! Error CheckTabel.sh formating outBgn=$outBgn cntIn=$cntIn wrong eDIVISOR TAB continue fi (( j = 0 )) for (( i = $outBgn ; i < cntIn ; i++ )) do # get name of output vars # echo "${eVarLine[$i]}=Set${i}" eVarOUT[$j]=${eVarLine[$i]} ((j++)) done eIsFind=0 # not finde yet # echo eVarIN ${#eVarIN[@]}: ${eVarIN[@]} ; echo eVarOUT ${#eVarOUT[@]}: ${eVarOUT[@]} ################################################################################### else if [[ "${Line:0:${#eEND}}" == "${eEND}" ]] # check for end of sentence then # echo "END: $Line" #echo "Line: ${Line:0:${#eEND}} == " # eISVAR=1 # source $eTmpFile #. data-file # execute file and set values for vars # > $eTmpFile # erase temporary file for setap vars continue # while read Line fi # #Check for error message and error vars set # if [[ "${Line:0:${#eERROR}}" == "${eERROR}" ]] # check for ERROR of sentence then # echo "<ERROR>:${eIsFind} $Line" #echo "Line: ${Line:0:${#eEND}} == " LineErr="" if [[ "eIsFind" -eq "0" ]] then ((CheckTabelErrors++)) LineErr="${Line#${eERROR}}" #remove <Error> echo "!!! ERROR CheckTabel.sh LineErr: ${eCurLine}" #;echo "Line: ${Line}" ErrVarOut="${LineErr#*${eInOutDevisor}}" #+ ${#eInOutDevisor}+ LineErr="${LineErr%${eInOutDevisor}*}" eDataOUT=( `echo "$ErrVarOut"` ) ( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done echo "${LineErr}" # error command ) >> $eTmpFile # create temporary file for setup vars and show error message fi # ---------- execute -------------- eISVAR=1 # its mean , that next line will with varnames source $eTmpFile #. data-file # execute file and set values for vars > $eTmpFile # erase temporary file for setap vars continue # while read Line fi #for skeep all next currient tabel parametrs if [[ "eIsFind" -eq "1" ]] then continue # while read Line fi eDatLine=( `echo "$Line"` ) # echo OUT ${#eDatLine[@]} ${eDatLine[@]} cntOut=${#eDatLine[@]} if (( $cntIn != $cntOut )) then echo !!! Error CheckTabel.sh in Conditions line=${eCurLine} formating Vars $cntIn but Data $cntOut, count of parametrs not equel ! ;echo !!! ${eVarIN[@]} === ${eDatLine[@]} continue # while read Line fi # # main check for compare tabale value and var value in currient string # ((cmpCnt=0)) for (( i = 0 ; i < cntOut ; i++ )) do #get input data if [ "${eDatLine[${i}]}" == "${eInOutDevisor}" ] ; then ((outBgn=i + 1)) break fi # echo DEBUG Element [$i]: ${eDatLine[$i]} val=${!eDatLine[$i]} eDatLine=${eDatLine[${i}]} == eVarDatIN="${eVarDatIN[$i]}" if [ "${eDatLine[${i}]}" == "${eVarDatIN[$i]}" ] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eANY}" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eNOTEMPTY}" && "${eVarDatIN[$i]}" != "" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi if [[ "${eDatLine[${i}]}" == "${eEMPTY}" && "${eVarDatIN[$i]}" == "" ]] ; then # echo ${eDatLine[${i}]} == ${eVarDatIN[$i]} ((cmpCnt++)) eDataIN[$i]=${eDatLine[${i}]} fi done # echo DEBUG "$cmpCnt" == "(($outBgn - 1 ))" outBgn=$outBgn cntIn=$cntIn if (( "$cmpCnt" == "(($outBgn - 1 ))" )) # there are data in this string #${#eVarIN[@]} then (( j = 0 )) for (( i = $outBgn ; i < cntOut ; i++ )) do # get value for output vars eDataOUT[$j]=${eDatLine[$i]} # echo "DEBUG ${eVarOUT[$j]}=${eDataOUT[$j]}" ((j++)) done ( for (( i = 0 ; i < ${#eVarOUT[@]} ; i++ )) do echo "${eVarOUT[$i]}=\"${eDataOUT[$i]}\"" done ) >> $eTmpFile # create temporary file for setap vars eIsFind=1 # echo OK: ${eVarIN[@]} == ${eDataIN[@]} '=>' ${eVarOUT[@]} == ${eDataOUT[@]} fi fi else #skeep empty and commets lines # echo Comment: $Line eDeb="" # for skeep warning fi done #while read Line ######################################################################3 IFS=$OLD_IFS #rm $eTmpFile
Source: https://habr.com/ru/post/172475/
All Articles