diff options
author | P. J. McDermott <pjm@nac.net> | 2012-10-23 23:02:31 (EDT) |
---|---|---|
committer | P. J. McDermott <pjm@nac.net> | 2012-10-23 23:02:31 (EDT) |
commit | e37e5752619499fdd34393e5aae9937d246e3cab (patch) | |
tree | ff3f9789cf45dc8d5367bc282dc9be8a309da2de /lib | |
parent | 4cbd2864e9623ea0d4ddc807eed64802aa17af17 (diff) |
Implement ob_set_substvar().
Diffstat (limited to 'lib')
-rw-r--r-- | lib/control.sh | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/control.sh b/lib/control.sh index 12dc8bd..15093a0 100644 --- a/lib/control.sh +++ b/lib/control.sh @@ -139,6 +139,36 @@ ${_obpco_line# }" return ${?} } +ob_set_substvar() +{ + _ob_local _obssv_name _obssv_value + + if [ ${#} -eq 2 ]; then + _obssv_name="${1}" + _obssv_value="${2}" + else + _ob_return 125 + return ${?} + fi + + # Trim leading and trailing whitespace from value. + _obssv_value="$(echo "${_obssv_value}" | sed -n ' + H; # Store each input line in the hold space. + ${ # At the last line of input, … + g; # … restore the hold space into the pattern space, … + s/^[ \t\n]*//; # … remove leading whitespace, … + s/[ \t\n]*$//; # … remove trailing whitespace, and … + p; # … print the results. + }; + ')" + + _obssv_name="$(echo "${_obssv_name}" | tr 'a-z-' 'A-Z_')" + eval "_OB_SUBSTVAR_${_obssv_name}='${_obssv_value}'" + + _ob_return 125 + return ${?} +} + _ob_parse_control_error() { _ob_local _obpcoe_file _obpcoe_line_nr _obpcoe_msg_id \ |