Next: , Previous: , Up: Top   [Contents][Index]


5 Encoding and decoding strings

The purpose of this module is to let an external process invoke a Bash script with damned command line arguments: strings including blanks or strange characters that may trigger quoting rules. This problem can arise when using scripting languages with some sort of eval command.

The solution is to encode the argument string in hexadecimal or octal format strings, so that all the damned characters are converted to “good” ones. The Bash script can convert them back.

NOTE Internally Bash represents strings as C language style ASCIIZ arrays, so it is impossible to correctly handle null bytes in a Bash variable: the string will get truncated at the null byte.

Function: mbfl_encode_hex ascii_string
Function: mbfl_encode_hex_var _RV ascii_string

Encode a hex string and outputs it on stdout.

The function variant _var stores the result in the variable _RV, rather than print it; Result variables.

Function: mbfl_decode_hex hex_string
Function: mbfl_decode_hex_var _RV hex_string

Decode a hex string and outputs it on stdout.

The function variant _var stores the result in the variable _RV, rather than print it; Result variables.

Function: mbfl_decode_oct oct_string
Function: mbfl_decode_oct_var _RV oct_string

Decode a oct string and outputs it on stdout.

The function variant _var stores the result in the variable _RV, rather than print it; Result variables.

Example:

mbfl_decode_hex 414243
-| ABC

Next: , Previous: , Up: Top   [Contents][Index]

This document describes version 3.0.0-devel.0 of Marcos Bash Functions Library.