рд╕рдорд╕реНрдпрд╛
рдбреНрдпреВрдЯреА рдкрд░, рдЖрдкрдХреЛ рд▓рд┐рдирдХреНрд╕ рдкрд░ рд╢реЗрд▓ рд╕реНрдХреНрд░рд┐рдкреНрдЯ рдХрд╛ рд╕рдХреНрд░рд┐рдп рд░реВрдк рд╕реЗ рдЙрдкрдпреЛрдЧ рдХрд░рдирд╛ рд╣реЛрдЧрд╛ред
рдЗрд╕ рддрдереНрдп рдХреЗ рдмрд╛рд╡рдЬреВрдж рдХрд┐ рд╕рднреА рд╕реНрдХреНрд░рд┐рдкреНрдЯ рдЕрдирд┐рд╡рд╛рд░реНрдп рд░реВрдк рд╕реЗ рдкреНрд░рдХреГрддрд┐ рдореЗрдВ рд╕рдорд╛рди рд╣реИрдВ - рдбреЗрдЯрд╛ рдкреАрдврд╝реАред рдЧреНрд░рд╛рд╣рдХ рд╕реЗ рдЗрдирдкреБрдЯ рдЬрд╛рдирдХрд╛рд░реА рдХреА рдЬрд╛рдБрдЪ рдХреА рд╢реБрджреНрдзрддрд╛ рдХреЛ рд▓рд┐рдЦрдиреЗ рдФрд░ рдбрд┐рдмрдЧ рдХрд░рдиреЗ рдореЗрдВ рдХрд╛рдлреА рд╕рдордп рд╡реНрдпрддреАрдд рд╣реЛрддрд╛ рд╣реИред рдФрд░ рддрджрдиреБрд╕рд╛рд░, рдЗрди рдЗрдирдкреБрдЯ рдорд╛рдкрджрдВрдбреЛрдВ рдХреЗ рдЖрдзрд╛рд░ рдкрд░ рдбреЗрдЯрд╛ рдкреАрдврд╝реА рдХреЗ рдорд╛рдкрджрдВрдбреЛрдВ рдХрд╛ рдирд┐рд░реНрдзрд╛рд░рдгред
рдЪреЗрдХ рд╡рд┐рд╢рд┐рд╖реНрдЯрддрд╛рдУрдВ рджреНрд╡рд╛рд░рд╛ рдкрд░рд┐рднрд╛рд╖рд┐рдд рд╕реНрдерд┐рд░ рдбреЗрдЯрд╛ рдкрд░ рдЖрдзрд╛рд░рд┐рдд рд╣реЛрддреЗ рд╣реИрдВ, рдЕрдХреНрд╕рд░ рддрд╛рд▓рд┐рдХрд╛рдУрдВ рдХреЗ рдкрд░рд┐рдгрд╛рдорд╕реНрд╡рд░реВрдк, рдЖрдЧреЗ рдХреА рдкреАрдврд╝реА рдХреЗ рд▓рд┐рдП рдирдП рдЖрд╡рд╢реНрдпрдХ рдкреИрд░рд╛рдореАрдЯрд░ рдЙрддреНрдкрдиреНрди рд╣реЛрддреЗ рд╣реИрдВред рдЙрд╕реА рд╕рдордп, рд╕рддреНрдпрд╛рдкрди рдЬрд╛рдирдХрд╛рд░реА рд╕реЗрдЯ рдХрд░рдиреЗ рдХреЗ рдХрд╛рд░реНрдп рдореЗрдВ рд╕рдЯреАрдХрддрд╛ рдФрд░ рджреЗрдЦрднрд╛рд▓ рдХреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рд╣реЛрддреА рд╣реИ, рдХреНрдпреЛрдВрдХрд┐ рд╕рдВрднрд╛рд╡рд┐рдд рддреНрд░реБрдЯрд┐рдпрд╛рдВ рдорд╣рдВрдЧреА рд╣реЛ рд╕рдХрддреА рд╣реИрдВред
рд╕рддреНрдпрд╛рдкрди рдЪрд░рдг рдореЗрдВ рдореБрдЦреНрдп рд░реВрдк рд╕реЗ рдиреЗрд╕реНрдЯреЗрдб рдХреЗрд╕ рдХреЛ рдЬрдорд╛ рдХрд░рдирд╛ рд╣реЛрддрд╛ рд╣реИ рдФрд░ рдпрджрд┐ рдирд┐рд░реНрдорд╛рдг рд╣реЛрддрд╛ рд╣реИред рдХрдЯ рд╕рд┐рд╕реНрдЯрдо (рддрд╛рд▓рд┐рдХрд╛)> рдХреЗ рдорд╛рдзреНрдпрдо рд╕реЗ рд▓реЗрдмрд▓ рдХреЛ рдкрд╛рд░реНрд╕ рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рдПрдХ рд╡рд┐рдЪрд╛рд░ рдерд╛> рддреЛ var1 var2 var3 рдкрдврд╝реЗрдВ, рдЕрдЧрд░, рдФрд░ рдлрд┐рд░ рдкрд░рд┐рдгрд╛рдо рдХреЛ рдХрд╣реАрдВ рдФрд░ рдмрдирд╛рддреЗ рд╣реИрдВ - рд▓реЗрдХрд┐рди рдпрд╣ рд╕рдм рдмрд╣реБрдд рд╕реБрд╡рд┐рдзрд╛рдЬрдирдХ рдирд╣реАрдВ рд╣реИ рдФрд░ рдирд╣реАрдВ рд╕реБрдВрджрд░, рдХрдо рд╕реЗ рдХрдо рд╡рд╛рдХреНрдпрд╡рд┐рдиреНрдпрд╛рд╕ рдХреА рддрд░рд╣ред
рдФрд░ рдПрдХ рд▓рдВрдмреЗ рд╕рдордп рдХреЗ рд▓рд┐рдП рдкрд╣рд▓реЗ рд╕реЗ рд╣реА ... "рджреЗрдЦрднрд╛рд▓ рдПрдХ рдорд┐рд╕реНрдЯреА рдХреЗ рджрд┐рд▓ рдореЗрдВ рд░рдЦрдирд╛ ..." (рдпрд╕рд┐рдирд┐рди рдПрд╕рдП), рд▓реЗрдХрд┐рди рдХреЛрдИ рдЕрдиреБрдХреВрд▓рди рд╕рдорд╛рдзрд╛рди рдирд╣реАрдВ рдерд╛ред
рдирд┐рд░реНрдгрдп, рд╣рдореЗрд╢рд╛ рдХреА рддрд░рд╣, рдЕрдЪрд╛рдирдХ рдЖрдпрд╛ред рд╢реЗрд▓ рдбреЙрдХ рдХреЗ рдорд╛рдзреНрдпрдо рд╕реЗ рдПрдХ рдмрд╛рд░ рдлрд┐рд░ рд╕реЗ рдЦреБрджрд╛рдИ рдХрд░рдирд╛ рдФрд░ рдПрдХ рдЪрд░ рдХреЛ рджреВрд╕рд░реЗ рдЪрд░ рдореЗрдВ рд╕реНрдерд┐рдд рдирд╛рдо рд╕реЗ рдПрдХреНрд╕реЗрд╕ рдХрд░рдиреЗ рдХреЗ рд╡рд┐рдЪрд╛рд░ рдХреЗ рдорд╛рдзреНрдпрдо рд╕реЗ рд╕реНрдХреНрд░реЙрд▓ рдХрд░рдирд╛, рдореБрдЭреЗ "рдЕрдкреНрд░рддреНрдпрдХреНрд╖ рд▓рд┐рдВрдХ" рдХрд╛ рд╡рд┐рд╖рдп рдорд┐рд▓рд╛! рд╢рд╛рдпрдж, рд╕рдореНрдорд╛рдирд┐рдд рдордВрдЪ рдЙрдкрдпреЛрдЧрдХрд░реНрддрд╛ рдРрд╕реА рд╢реЗрд▓ рд╕реБрд╡рд┐рдзрд╛ рд╕реЗ рдкрд░рд┐рдЪрд┐рдд рд╣реИрдВ, рд▓реЗрдХрд┐рди рдЙрди рд▓реЛрдЧреЛрдВ рдХреЗ рд▓рд┐рдП рдЬреЛ рдЗрд╕ рдЬрд╛рдирдХрд╛рд░реА рдореЗрдВ рдирд╣реАрдВ рд╣реИрдВ, рдПрдХ рдЫреЛрдЯрд╛ рд╡реНрдпрд╛рдЦреНрдпрд╛ рдЙрджрд╛рд╣рд░рдг:
рдЕрдкреНрд░рддреНрдпрдХреНрд╖ рдЪрд░ рд╕рдВрджрд░реНрдн
рдкрд░рд┐рдгрд╛рдо:
name_of_var = рд╡рд╛рд░
рдЕрдм рд╡реИрд▓ = var_value
рдирдП рд╕рдВрд╕реНрдХрд░рдг рджреНрд╡рд╛рд░рд╛ рдЕрдм val = var_value
рдФрд░ рдлрд┐рд░ рдпрд╣ рдЪрд▓рд╛ рдЧрдпрд╛
рдХрд╛рд░реНрдп рд╡рд┐рд╡рд░рдг рдХреЗ рд▓рд┐рдП рдПрдХ рд╕реБрдВрджрд░ рд╡рд╛рдХреНрдпрд╡рд┐рдиреНрдпрд╛рд╕ рдмрдирд╛рдиреЗ рдХрд╛ рдирд┐рд░реНрдгрдп рд▓рд┐рдпрд╛ рдЧрдпрд╛, рдФрд░ рдЗрд╕рдХрд╛ рдПрдХ рдЕрдЪреНрдЫрд╛ рд╡рд┐рд╢реНрд▓реЗрд╖рдг рд▓рд┐рдЦрд╛ рдЧрдпрд╛ред
рдЕрдзрд┐рдХрд╛рдВрд╢ рд╢рд░реНрддреЗрдВ рдЖрд╕рд╛рдиреА рд╕реЗ рдЗрдирдкреБрдЯ рдорд╛рдиреЛрдВ рдХреА рддрд╛рд▓рд┐рдХрд╛ рдореЗрдВ рдлрд┐рдЯ рд╣реЛ рдЬрд╛рддреА рд╣реИрдВ, рдФрд░ рдЖрдЙрдЯрдкреБрдЯ рдирд┐рд░реНрднрд░рддрд╛ рднреА рдЙрд▓реНрд▓реЗрдЦрдиреАрдп рд░реВрдк рд╕реЗ рддрд╛рд▓рд┐рдХрд╛ рдореЗрдВ рдмрджрд▓ рдЬрд╛рддреА рд╣реИред рдЖрдЧреЗ рддрд░реНрдХ рдХрд░рдирд╛ред рдЗрдирдкреБрдЯ рдЬрд╛рдирдХрд╛рд░реА рдФрд░ рдПрдХ рдкрдВрдХреНрддрд┐ рдореЗрдВ рд╕рдВрдмрдВрдзрд┐рдд рдЖрдЙрдЯрдкреБрдЯ рдЙрддреНрдХреГрд╖реНрдЯ рд╣реИред рдПрдХ рд╕реБрдВрджрд░ рд╡рд┐рднрд╛рдЬрдХ рдХреА рдЬрд░реВрд░рдд рд╣реИред рд╡рд┐рднрд╛рдЬрдХ "=>" рдЧрдгрд┐рдд рдореЗрдВ рдирд┐рдореНрдирд▓рд┐рдЦрд┐рдд рдХреЗ рдкреНрд░рддреАрдХ рджреНрд╡рд╛рд░рд╛ рдмрдирд╛рдпрд╛ рдЧрдпрд╛ рд╣реИ, рдФрд░ рдпрд╣рд╛рдБ рдРрд╕рд╛ рд▓рдЧрддрд╛ рд╣реИ рдХрд┐ рдЗрд╕реА рдЖрдЙрдЯрдкреБрдЯ рдкреИрд░рд╛рдореАрдЯрд░ рдЗрдирдкреБрдЯ рдорд╛рдкрджрдВрдбреЛрдВ рдХреЗ рдПрдХ рд╕реЗрдЯ рд╕реЗ рдЕрдиреБрд╕рд░рдг рдХрд░рддреЗ рд╣реИрдВред
рд╡рд╛рдХреНрдп рд░рдЪрдирд╛:
рд╕рд╛рд░рдгреАрдпрди рдХреЗ рдорд╛рдзреНрдпрдо рд╕реЗ рдЗрдирдкреБрдЯ рдЪрд░ рдХреЗ рдирд╛рдо
= рд╕рд╛рд░рдгреАрдХрд░рдг рдХреЗ рдорд╛рдзреНрдпрдо рд╕реЗ рдЖрдЙрдЯрдкреБрдЯ рдЪрд░ рдХреЗ рдирд╛рдо
рд╕рд╛рд░рдгреАрдХрд░рдг рдХреЗ рдорд╛рдзреНрдпрдо рд╕реЗ рдЗрдирдкреБрдЯ рдорд╛рдкрджрдВрдбреЛрдВ рдХрд╛ рдорд╛рди
=> рдЗрд╕реА рдЙрддреНрдкрд╛рджрди рдореВрд▓реНрдпреЛрдВ рдХреЛ рд╕рд╛рд░рдгреАрдХрд░рдг
рд╢рд╛рдпрдж backquotes рдореЗрдВ рдПрдХ рдЧрдгрдирд╛ рдЕрднрд┐рд╡реНрдпрдХреНрддрд┐ `[рдХреБрдЫ рдХреА рдЧрдгрдирд╛]`ред
рдЦрд╛рд▓реА рд▓рд╛рдЗрдиреЛрдВ рдФрд░ "#" рд╡рд░реНрдг рд╕реЗ рд╢реБрд░реВ рд╣реЛрдиреЗ рд╡рд╛рд▓реА рд▓рд╛рдЗрдиреЗрдВ рд╕рдВрд╕рд╛рдзрд┐рдд рдирд╣реАрдВ рд╣реЛрддреА рд╣реИрдВред
рдЯреИрдм рд╕реАрдорд╛рдВрдХрдХред
рд╣рд╛рд▓рдд рдмреНрд▓реЙрдХ рдПрдХ рд╡рд┐рд╢реЗрд╖ рдЕрднрд┐рд╡реНрдпрдХреНрддрд┐ рдХреЗ рд╕рд╛рде рд╕рдорд╛рдкреНрдд рд╣реЛрддрд╛ рд╣реИ
, => .
.
:
<?> - ; <_>- ; <.>- .
, , , .
, 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 '
рд╣рд╛рд▓рдд рдмрди рдЧрдИ рд╣реИ рдФрд░ рдЕрдм рд╣рдо CheckTabel.sh рд╣реИрдВрдбрд▓рд░ рдЪрд▓рд╛рддреЗ рд╣реИрдВ рдФрд░ рдкрд░рд┐рдгрд╛рдо рдкреНрд░рджрд░реНрд╢рд┐рдд рдХрд░рддреЗ рд╣реИрдВ:
source $HOME/bin/CheckTabel.sh
рдкрд░рд┐рдгрд╛рдо:
рддреЛрдбреЛ = рдЧрддрд┐ рдзреАрдореА рдХрд░реЛ = рдзреАрдорд╛ рдХрд░реЛ
рдЙрджрд╛рд╣рд░рдг рдХреЗ рдкреВрд░реНрдг рдкрд╛рда Test.sh
рдкрд░рд┐рдгрд╛рдо:
рддреЛрдбреЛ = рдЧрддрд┐ рдзреАрдореА рдХрд░реЛ = рдзреАрдорд╛ рдХрд░реЛ
рд╡рд┐рдХрд▓реНрдк:
рдЯреЛрдбреЛ = рдмреНрд░реЗрдХ рд╕реНрдкреАрдб = рд╕реНрдЯреИрдВрдб
рдпрд╣рд╛рдВ рд╣рдо рдПрдХ рдЕрд▓рдЧ рдкрд░рд┐рдгрд╛рдо рджреЗрдЦрддреЗ рд╣реИрдВ, рдХреНрдпреЛрдВрдХрд┐ рдкрд╣рд▓реА рд╕реНрдерд┐рддрд┐ рдХреЗ рдмрд╛рдж рд╕реНрдкреАрдб рдорд╛рди рдмрджрд▓ рдЧрдпрд╛ рд╣реИред
рдпрд╣ рдХреИрд╕реЗ рдХрд╛рдо рдХрд░рддрд╛ рд╣реИ
рдЕрдм рд╕рдВрдХреНрд╖реЗрдк рдореЗрдВ, CheckTabel.sh рдХрд╛ рдкреНрд░рд╕рдВрд╕реНрдХрд░рдг рдХреНрдпрд╛ рдХрд░рддрд╛ рд╣реИ, рд▓реЗрдЦ рдХреЗ рдЕрдВрдд рдореЗрдВ рдкреВрд░рд╛ рдкрд╛рдаред
рд╢реБрд░реБрдЖрдд рдореЗрдВ, рдкреБрд░рд╛рдиреЗ рдЯреИрдм рдХреЛ рд╕рд╣реЗрдЬрд╛ рдЧрдпрд╛ рдерд╛ рдФрд░ рдПрдХ рдирдпрд╛ рдЯреИрдм рд╕реАрдорд╛рдВрдХрдХ рд╕реЗрдЯ рдХрд┐рдпрд╛ рдЧрдпрд╛ рдерд╛ред
рдЕрдЧрд▓рд╛, $ рдХрдВрдбреАрд╢рди рд╕реЗ рд▓рд╛рдЗрди рджреНрд╡рд╛рд░рд╛ рд▓рд╛рдЗрди рдкрдврд╝реЗрдВ рдФрд░ рд▓рд╛рдЗрди рдореЗрдВ рдкреВрд░реЗ рд╕реНрдЯреНрд░рд┐рдВрдЧ рдХреЛ рд╕реЗрд╡ рдХрд░реЗрдВред
echo "${Conditions}" | while read Line do тАж done
рдореБрдЭреЗ рдирд╣реАрдВ рдкрддрд╛ рдерд╛ рдХрд┐ рдЪрд░ рдХреЗ рдореВрд▓реНрдпреЛрдВ рдХреЛ рдЗрддрдиреА рдЖрд╕рд╛рдиреА рд╕реЗ рдПрдХ рдиреЗрд╕реНрдЯреЗрдб рд╕реНрдХреНрд░рд┐рдкреНрдЯ рд╕реЗ рдкреНрд░рд╛рдкреНрдд рдХрд┐рдпрд╛ рдЬрд╛ рд╕рдХрддрд╛ рд╣реИ, рдФрд░ рдпрд╣ рдмрд╛рдж рдореЗрдВ рдХрд╛рдо рдЖрдПрдЧрд╛ред
рдЕрдВрджрд░ рдореИрдВ рд╕реВрдХреНрд╖реНрдо, рдореЗрд░реЗ рд╡рд┐рдЪрд╛рд░ рд╕реЗ, рдХреНрд╖рдгреЛрдВ рдХрд╛ рд╡рд░реНрдгрди рдХрд░реВрдВрдЧрд╛ред
рд╣рдо рдЦрд╛рд▓реА рд▓рд╛рдЗрдиреЛрдВ, рдЯрд┐рдкреНрдкрдгрд┐рдпреЛрдВ рдФрд░ рдЕрдиреНрдп рдЕрдирд╛рд╡рд╢реНрдпрдХ рд▓реЛрдЧреЛрдВ рдХреЛ рдЫреЛрдбрд╝ рджреЗрддреЗ рд╣реИрдВред
рд╣рдо рдкреНрд░рддреНрдпреЗрдХ рдкрдВрдХреНрддрд┐ рдХреЛ рдЯреИрдм рджреНрд╡рд╛рд░рд╛ рдЕрд▓рдЧ рдХрд┐рдП рдЧрдП рдорд╛рдкрджрдВрдбреЛрдВ рдореЗрдВ рддреЛрдбрд╝рддреЗ рд╣реИрдВ рдФрд░ рдорд╛рдкрджрдВрдбреЛрдВ рдХреЛ рдПрдХ рд╕рд░рдгреА рдореЗрдВ рдЪрд▓рд╛рддреЗ рд╣реИрдВред рд╣рдо рдЖрд╡рд╢реНрдпрдХ рд▓рд╛рдЗрдиреЛрдВ рд╕реЗ рдЪрд░ рдирд╛рдо рдирд┐рдХрд╛рд▓рддреЗ рд╣реИрдВред рдпрд╣ рдореЗрд░реЗ рд▓рд┐рдП рдЗрд╕ рддрд░рд╣ рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИ:
eVarLine=(`echo "$Line"`)
рдЖрдЧреЗ рджрд┐рд▓рдЪрд╕реНрдк рд╣реИ, рдЪрд░ рдХреЗ рдЕрдкреНрд░рддреНрдпрдХреНрд╖ рд╕рдВрджрд░реНрднреЛрдВ рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рддреЗ рд╣реБрдП, рд╣рдо рдЗрдирдкреБрдЯ рдкреИрд░рд╛рдореАрдЯрд░ eVarDatIN рдХреЗ рдореВрд▓реНрдпреЛрдВ рдХреА рдПрдХ рд╕рд░рдгреА рдмрдирд╛рддреЗ рд╣реИрдВред
tmp=${eVarLine[$i]}
=> рдкреНрд░рддреАрдХ рдЖрдЙрдЯрдкреБрдЯ рдХреЗ рдмрд╛рдж рдкрд░рд┐рд╡рд░реНрддрдиреАрдп рдирд╛рдо рд╣реИрдВ, рд╣рдо рдЙрдиреНрд╣реЗрдВ eVarOUT рд╕рд░рдгреА рдореЗрдВ рд╕рд╣реЗрдЬрддреЗ рд╣реИрдВред
рд▓реВрдк рдореЗрдВ рдорд╛рди рдХреЗ рд╕рд╛рде рдкрдВрдХреНрддрд┐рдпреЛрдВ рд╕реЗ, рд╣рдо рдЪрд░ рдХреЗ рдорд╛рдиреЛрдВ рдХреЛ рдирд┐рдХрд╛рд▓рддреЗ рд╣реИрдВ, рдФрд░ eDatLine рд╕рд░рдгреА рдореЗрдВ рд▓рд┐рдЦрддреЗ рд╣реИрдВред
eDatLine=( `echo "$Line"` )
рд╣рдо рдЗрди рдореВрд▓реНрдпреЛрдВ рдХреА рддреБрд▓рдирд╛ eVarDatIN рдореЗрдВ рд╕рдВрдЧреНрд░рд╣реАрдд рдЗрдирдкреБрдЯ рдорд╛рдкрджрдВрдбреЛрдВ рдХреЗ рдореВрд▓реНрдпреЛрдВ рд╕реЗ рдХрд░рддреЗ рд╣реИрдВ, рдпрджрд┐ рдорд╛рди рджрд┐рдП рдЧрдП рдкреИрдЯрд░реНрди рд╕реЗ рдореЗрд▓ рдЦрд╛рддреЗ рд╣реИрдВ (<!>, <<>, <_>), рддреЛ рд╣рдо рдбреЗрдЯрд╛ рдорд╛рдиреЛрдВ рдХреЗ рд╕рд╛рде рд╕рд░рдгреА рдХреЛ рднрд░рддреЗ рд╣реИрдВред рдпрджрд┐ рд╕рдм рдХреБрдЫ рдореЗрд▓ рдЦрд╛рддрд╛ рд╣реИ, рддреЛ рд╣рдо рдмрд╛рд╣рд░ рдЧрд┐рд░рддреЗ рд╣реИрдВ, рдпрджрд┐ рдирд╣реАрдВ, рддреЛ рд╣рдо рд▓рд╛рдЗрди рдкрд░ рдкрд╣реБрдВрдЪрддреЗ рд╣реИрдВред
.
.
, тАУ ? , , .
, , .
( 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