# HG changeset patch # User František Kučera # Date 1726599572 -7200 # Node ID 037d61c9e448f20784a6af8cb9fb0fc55db8f3fd # Parent 536f9116a52c5574a94263fc3e99aced1d06a9ca bash: basic shell version diff -r 536f9116a52c -r 037d61c9e448 bash/parameter-lister/parameter-lister.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bash/parameter-lister/parameter-lister.sh Tue Sep 17 20:59:32 2024 +0200 @@ -0,0 +1,55 @@ +#!/bin/bash +# parameter-lister +# Copyright © 2024 František Kučera (Frantovo.cz, GlobalCode.info) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +_parameter_lister_terminal() { + for ((i=0;i<=$#;i++)); do + echo " argv[$i] = ${!i}" + done; +} + +_escape_xml() { + sed \ + -e 's/&/\&/g' \ + -e 's//\>/g' \ + -e 's/"/\"/g' \ + -e "s/'/\\'/g" +} + +_parameter_lister_xml() { + echo "" + for ((i=0;i<=$#;i++)); do + echo -ne "\t" + echo -n "${!i}" | _escape_xml + echo "" + done; + echo "" +} + +# terminal output is default +_parameter_lister_() { + _parameter_lister_terminal "${@}" +} + +fx="_parameter_lister_$PARAMETER_LISTER_OUTPUT" + +if type "$fx" &> /dev/null; then + $fx "${@}" +else + echo "Unsupported output: $PARAMETER_LISTER_OUTPUT" + exit 1; +fi diff -r 536f9116a52c -r 037d61c9e448 bash/parameter-lister/start.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bash/parameter-lister/start.sh Tue Sep 17 20:59:32 2024 +0200 @@ -0,0 +1,14 @@ +#!/bin/sh + +# syntax highlight: +# ./start.sh | pygmentize -l xml + +p1="aaa"; +p2="first line +second line +third line"; +p3="a & b >> OMG <<"; + +export PARAMETER_LISTER_OUTPUT="xml"; + +./parameter-lister.sh "$p1" "$p2" "$p3";