bash: basic shell version default tip
authorFrantišek Kučera <franta-hg@frantovo.cz>
Tue, 17 Sep 2024 20:59:32 +0200
changeset 31037d61c9e448
parent 30 536f9116a52c
bash: basic shell version
bash/parameter-lister/parameter-lister.sh
bash/parameter-lister/start.sh
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/bash/parameter-lister/parameter-lister.sh	Tue Sep 17 20:59:32 2024 +0200
     1.3 @@ -0,0 +1,55 @@
     1.4 +#!/bin/bash
     1.5 +# parameter-lister
     1.6 +# Copyright © 2024 František Kučera (Frantovo.cz, GlobalCode.info)
     1.7 +#
     1.8 +# This program is free software: you can redistribute it and/or modify
     1.9 +# it under the terms of the GNU General Public License as published by
    1.10 +# the Free Software Foundation, version 3 of the License.
    1.11 +#
    1.12 +# This program is distributed in the hope that it will be useful,
    1.13 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    1.15 +# GNU General Public License for more details.
    1.16 +#
    1.17 +# You should have received a copy of the GNU General Public License
    1.18 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
    1.19 +
    1.20 +
    1.21 +_parameter_lister_terminal() {
    1.22 +	for ((i=0;i<=$#;i++)); do
    1.23 +		echo "  argv[$i] = ${!i}"
    1.24 +	done;
    1.25 +}
    1.26 +
    1.27 +_escape_xml() {
    1.28 +	sed \
    1.29 +		-e 's/&/\&amp;/g'     \
    1.30 +		-e 's/</\&lt;/g'      \
    1.31 +		-e 's/>/\&gt;/g'      \
    1.32 +		-e 's/"/\&quot;/g'    \
    1.33 +		-e "s/'/\\&apos;/g"
    1.34 +}
    1.35 +
    1.36 +_parameter_lister_xml() {
    1.37 +	echo "<parameters>"
    1.38 +	for ((i=0;i<=$#;i++)); do
    1.39 +		echo -ne "\t<parameter>"
    1.40 +		echo -n  "${!i}" | _escape_xml
    1.41 +		echo      "</parameter>"
    1.42 +	done;
    1.43 +	echo "</parameters>"
    1.44 +}
    1.45 +
    1.46 +# terminal output is default
    1.47 +_parameter_lister_() {
    1.48 +	_parameter_lister_terminal "${@}"
    1.49 +}
    1.50 +
    1.51 +fx="_parameter_lister_$PARAMETER_LISTER_OUTPUT"
    1.52 +
    1.53 +if type "$fx" &> /dev/null; then
    1.54 +	$fx "${@}"
    1.55 +else
    1.56 +	echo "Unsupported output: $PARAMETER_LISTER_OUTPUT"
    1.57 +	exit 1;
    1.58 +fi
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/bash/parameter-lister/start.sh	Tue Sep 17 20:59:32 2024 +0200
     2.3 @@ -0,0 +1,14 @@
     2.4 +#!/bin/sh
     2.5 +
     2.6 +# syntax highlight:
     2.7 +# ./start.sh | pygmentize -l xml
     2.8 +
     2.9 +p1="aaa";
    2.10 +p2="first line
    2.11 +second line
    2.12 +third line";
    2.13 +p3="a & b >> OMG <<";
    2.14 +
    2.15 +export PARAMETER_LISTER_OUTPUT="xml";
    2.16 +
    2.17 +./parameter-lister.sh "$p1" "$p2" "$p3";