Jonathan Hart | 518e5e7 | 2014-10-31 15:28:35 -0700 | [diff] [blame] | 1 | #!/bin/bash |
2 | |||||
3 | validate_number () { | ||||
4 | local re="^[0-9]+$" | ||||
5 | if [[ ! $1 =~ $re ]] ; then | ||||
Thomas Vachuska | 1c188d3 | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 6 | return 1 |
Jonathan Hart | 518e5e7 | 2014-10-31 15:28:35 -0700 | [diff] [blame] | 7 | fi |
Jonathan Hart | 518e5e7 | 2014-10-31 15:28:35 -0700 | [diff] [blame] | 8 | return 0 |
9 | } | ||||
10 | |||||
11 | find_node () { | ||||
12 | if validate_number $1 ; then | ||||
Thomas Vachuska | 1c188d3 | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 13 | # input is a number, try to find if an OC node is defined |
14 | oc_try="OC$1" | ||||
15 | node=${!oc_try} | ||||
Jonathan Hart | 518e5e7 | 2014-10-31 15:28:35 -0700 | [diff] [blame] | 16 | |
Thomas Vachuska | 1c188d3 | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 17 | if [ -n "$node" ]; then |
18 | # node lookup succeeded, return node | ||||
19 | echo $node | ||||
20 | else | ||||
21 | # node lookup failed, return original input | ||||
22 | echo $1 | ||||
23 | fi | ||||
Jonathan Hart | 518e5e7 | 2014-10-31 15:28:35 -0700 | [diff] [blame] | 24 | else |
Thomas Vachuska | 1c188d3 | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 25 | echo $1 |
Jonathan Hart | 518e5e7 | 2014-10-31 15:28:35 -0700 | [diff] [blame] | 26 | fi |
Jonathan Hart | 518e5e7 | 2014-10-31 15:28:35 -0700 | [diff] [blame] | 27 | return 0 |
28 | } |