#!/bin/sh # License: LGPLv2 # _ #[ ] #[_] # # ] # ] # _ # _] #[_ # _ # _] # _] # #[_] # ] # _ #[_ # _] # _ #[_ #[_] # _ # ] # ] # _ #[_] #[_] # _ #[_] # ] #!/bin/sh # This script is pretty useless actually but # demonstrates a couple of concepts: # a. self referencing # b. getting range of lines from a file # # example usage is: # clear; for i in `seq 0 9`; do ./7seg $i; sleep 1; clear; done matchstr $1 { [0-9] { } * { echo "Usage is $0 num, where num is 0 to 9" > !2; exit 1} } global num_plus_one := $[expr $1 + 1] global lines_minus_one := $[expr $num_plus_one '*' 3] head -$[expr $lines_minus_one + 1] $[which $0] | tail -3 | cut -b2- (CommandList children: [ (Case to_match: {($ VSub_Number "$1")} arms: [ (case_arm pat_list:[{(Lit_Other "[") (0-9) (Lit_Other "]")}] spids:[131134136-1]) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (Sentence child: (SimpleCommand words: [ {(echo)} {(DQ ("Usage is ") ($ VSub_Number "$0") (" num, where num is 0 to 9"))} ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[150])] ) terminator: ) (C {(exit)} {(1)}) ] spids: [139 140 157 -1] ) ] spids: [124 128 159] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:num_plus_one) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(expr)} {($ VSub_Number "$1")} {(Lit_Other "+")} {(1)})] ) left_token: spids: [163 171] ) } spids: [162] ) ] spids: [162] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:lines_minus_one) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(expr)} {($ VSub_Name "$num_plus_one")} {(EscapedLiteralPart token:)} {(3)} ) ] ) left_token: spids: [174 182] ) } spids: [173] ) ] spids: [173] ) (Pipeline children: [ (C {(head)} {(-) (CommandSubPart command_list: (CommandList children: [(C {(expr)} {($ VSub_Name "$lines_minus_one")} {(Lit_Other "+")} {(1)})] ) left_token: spids: [187 195] ) } { (CommandSubPart command_list: (CommandList children:[(C {(which)} {($ VSub_Number "$0")})]) left_token: spids: [197 201] ) } ) (C {(tail)} {(-3)}) (C {(cut)} {(-b2-)}) ] negated: False ) ] )