📜 ⬆️ ⬇️

Check input parameters or indirect references to BASH

Problem

On duty, you have to actively use Shell scripts on Linux OS.
Moreover, all scripts are essentially the same in their essence - data generation. A considerable amount of time is spent on writing and debugging the correctness of the verification of input information from the customer. And accordingly, the definition of data generation parameters based on these input parameters.

The checks are based on static data defined by specifications, often tables, as a result of reconciliations new necessary parameters are generated for further generation. At the same time, the work on setting up verification information requires accuracy and care, since possible errors can be costly.
The verification stage mainly consists of cluttering up the case and if nested constructions. There was an idea to parse the plates through the system cut (table)> read var1 var2 var3 then if -s, and then form the result somewhere - but all this is not very convenient and not nice, like minimal syntax.

And for a long time already "... care lay in the heart of a hazy ..." (Yesenin SA), and there was still no optimization solution.

The decision, as always, came suddenly. Digging the docks over the shell one more time and scrolling through the idea of ​​accessing a variable by its name located in another variable - found the topic “indirect references”! Perhaps, dear forum users are familiar with this opportunity shell, but for those who do not know, a small explanatory example:
')
Indirect variable references
#!/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" 

Result:
name_of_var = Var
Now val = var_value
by new version now val = var_value


And then suffered

It was decided to make a beautiful syntax of the task description, and write a good analysis of it.
Most of the conditions easily fit into the table of input values, and the output dependency is also remarkably formed in the table. Reasoning further. The input information and the corresponding output in one line is excellent. Need a beautiful separator. The delimiter made “=>” the following character in mathematics, and here it seems like the corresponding output parameters follow from one set of input parameters.

Syntax:

Names of input variables through tabulation => names of output variables through tabulation
Values ​​of input parameters through tabulation => tabulation corresponding output values
Perhaps a calculated expression in reverse quotes `[something to calculate]`.
Blank lines and lines starting with the “#” character are not processed.
Tab delimiter.
 # 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 

The condition block ends with a special expression.
          ,   =>       . 
.
:
<?> - ; <_>- ; <.>- .
, , , .

, 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=


Next, validation of the parameter values ​​is performed.
The if else construct is usually used, and the case can also be:
 if [[ "$Speed" == "" ]] || [[ "$Speed" == "" ]] || [[ "$Speed" == "" ]] then echo "Speed ok" else echo "Wrong Speed:${Speed}.";exit 0; fi 


But I liked it in a new way, although it is necessary to follow the syntax and enter the auxiliary variable Result.
Further condition consisting of two: checking the correctness of the parameter Speed
and the actual basic condition for finding the necessary action:
 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 ' 

The condition is formed and now we run the CheckTabel.sh handler and display the result:
 source $HOME/bin/CheckTabel.sh # execute check and set values for vars echo "Todo=$ToDo Speed=$Speed " 

Result:
Todo = slow down Speed ​​= slow

The full text of the Test.sh example
 #!/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 

Result:
Todo = slow down Speed ​​= slow
alternative:
Todo = slow down Speed ​​= stand

Here we see a different result, because the Speed ​​value after the first condition has changed.


How it works

Now briefly, what does the processing CheckTabel.sh, the full text at the end of the article.
At the beginning, the old tabulation separator was saved and installed.
 #echo ifs=$IFS OLD_IFS="$IFS" IFS=$' '# 

Further we read from $ Conditions line by line and we save lines entirely in Line.
 echo "${Conditions}" | while read Line do …   done #while read Line 

I did not know that the values ​​of variables can be so easily obtained in a nested script from the callee, and this will come in handy later.

Inside I will describe the thin, in my opinion, moments.

We skip blank lines, lines with comments and other non-usefulness.

We divide each line into parameters separated by tabs and drive parameters into an array. From the necessary lines we retrieve variable names. I do it this way:
 eVarLine=(`echo "$Line"`) 


Further interesting, in a cycle using indirect references to variables, we form an array of values ​​of input parameters eVarDatIN.
  tmp=${eVarLine[$i]} # get name of input var eval tmp=\$$tmp # gat var value by var name eVarDatIN[${i}]=${tmp} 

Variable names after the symbol => are output, they are stored in the array eVarOUT.

From the rows with values ​​in the loop, we retrieve the values ​​of the variables, and write to the eDatLine array.
 eDatLine=( `echo "$Line"` ) 

We compare these values ​​with the values ​​of the input parameters saved in eVarDatIN, if the values ​​match the patterns (<?>, <.>, <_>), Then type the DataOUT array with the values. If everything matches, drop out, if not, we’ll reach the 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