Improve pretty-printing of command line string
Use the suggestion "If you want to print the argument list as close as possible to what the user probably entered" from http://stackoverflow.com/questions/10835933/preserve-quotes-in-bash-arguments to create `$CMDLINE` and to print the command lines in `run_mass_testing()` and `run_mass_testing_parallel()`.
This commit is contained in:
parent
7cbce9cb55
commit
6633d0e549
34
testssl.sh
34
testssl.sh
|
@ -116,7 +116,7 @@ OPENSSL_LOCATION=""
|
||||||
HNAME="$(hostname)"
|
HNAME="$(hostname)"
|
||||||
HNAME="${HNAME%%.*}"
|
HNAME="${HNAME%%.*}"
|
||||||
|
|
||||||
readonly CMDLINE="$@"
|
declare CMDLINE
|
||||||
# When performing mass testing, the child processes need to be sent the
|
# When performing mass testing, the child processes need to be sent the
|
||||||
# command line in the form of an array (see #702 and http://mywiki.wooledge.org/BashFAQ/050).
|
# command line in the form of an array (see #702 and http://mywiki.wooledge.org/BashFAQ/050).
|
||||||
readonly -a CMDLINE_ARRAY=("$@")
|
readonly -a CMDLINE_ARRAY=("$@")
|
||||||
|
@ -11746,7 +11746,7 @@ create_mass_testing_cmdline() {
|
||||||
}
|
}
|
||||||
|
|
||||||
run_mass_testing() {
|
run_mass_testing() {
|
||||||
local cmd cmdline=""
|
local cmdline=""
|
||||||
local first=true
|
local first=true
|
||||||
|
|
||||||
if [[ ! -r "$FNAME" ]] && "$IKNOW_FNAME"; then
|
if [[ ! -r "$FNAME" ]] && "$IKNOW_FNAME"; then
|
||||||
|
@ -11761,8 +11761,7 @@ run_mass_testing() {
|
||||||
# Create the command line for the child in the form of an array (see #702)
|
# Create the command line for the child in the form of an array (see #702)
|
||||||
create_mass_testing_cmdline "serial" $cmdline
|
create_mass_testing_cmdline "serial" $cmdline
|
||||||
draw_line "=" $((TERM_WIDTH / 2)); outln;
|
draw_line "=" $((TERM_WIDTH / 2)); outln;
|
||||||
# See http://stackoverflow.com/questions/10835933/preserve-quotes-in-bash-arguments
|
outln "$(create_cmd_line_string "$0" "${MASS_TESTING_CMDLINE[@]}")"
|
||||||
outln "$(strip_leading_space "$(printf " %q" "$0" "${MASS_TESTING_CMDLINE[@]}")")"
|
|
||||||
"$first" || fileout_separator # this is needed for appended output, see #687
|
"$first" || fileout_separator # this is needed for appended output, see #687
|
||||||
CHILD_MASS_TESTING=true "$0" "${MASS_TESTING_CMDLINE[@]}" # we call ourselves here. $do_mass_testing is the parent, $CHILD_MASS_TESTING... you figured
|
CHILD_MASS_TESTING=true "$0" "${MASS_TESTING_CMDLINE[@]}" # we call ourselves here. $do_mass_testing is the parent, $CHILD_MASS_TESTING... you figured
|
||||||
first=false
|
first=false
|
||||||
|
@ -11785,7 +11784,7 @@ get_next_message_testing_parallel_result() {
|
||||||
|
|
||||||
#FIXME: not called/tested yet
|
#FIXME: not called/tested yet
|
||||||
run_mass_testing_parallel() {
|
run_mass_testing_parallel() {
|
||||||
local cmd cmdline=""
|
local cmdline=""
|
||||||
|
|
||||||
if [[ ! -r "$FNAME" ]] && $IKNOW_FNAME; then
|
if [[ ! -r "$FNAME" ]] && $IKNOW_FNAME; then
|
||||||
fatal "Can't read file \"$FNAME\"" "2"
|
fatal "Can't read file \"$FNAME\"" "2"
|
||||||
|
@ -11802,8 +11801,7 @@ run_mass_testing_parallel() {
|
||||||
# fileout() won't include the "service" information in the JSON file for the child process
|
# fileout() won't include the "service" information in the JSON file for the child process
|
||||||
# if the JSON file doesn't already exist.
|
# if the JSON file doesn't already exist.
|
||||||
"$JSONHEADER" && echo -n "" > "$TEMPDIR/jsonfile_$(printf "%08d" $NR_PARALLEL_TESTS).json"
|
"$JSONHEADER" && echo -n "" > "$TEMPDIR/jsonfile_$(printf "%08d" $NR_PARALLEL_TESTS).json"
|
||||||
# See http://stackoverflow.com/questions/10835933/preserve-quotes-in-bash-arguments
|
PARALLEL_TESTING_CMDLINE[NR_PARALLEL_TESTS]="$(create_cmd_line_string "$0" "${MASS_TESTING_CMDLINE[@]}")"
|
||||||
PARALLEL_TESTING_CMDLINE[NR_PARALLEL_TESTS]="$(strip_leading_space "$(printf " %q" "$0" "${MASS_TESTING_CMDLINE[@]}")")"
|
|
||||||
CHILD_MASS_TESTING=true "$0" "${MASS_TESTING_CMDLINE[@]}" > "$TEMPDIR/term_output_$(printf "%08d" $NR_PARALLEL_TESTS).log" &
|
CHILD_MASS_TESTING=true "$0" "${MASS_TESTING_CMDLINE[@]}" > "$TEMPDIR/term_output_$(printf "%08d" $NR_PARALLEL_TESTS).log" &
|
||||||
PARALLEL_TESTING_PID[NR_PARALLEL_TESTS]=$!
|
PARALLEL_TESTING_PID[NR_PARALLEL_TESTS]=$!
|
||||||
NR_PARALLEL_TESTS+=1
|
NR_PARALLEL_TESTS+=1
|
||||||
|
@ -11949,8 +11947,30 @@ parse_opt_equal_sign() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Create the command line string for printing purposes
|
||||||
|
# See http://stackoverflow.com/questions/10835933/preserve-quotes-in-bash-arguments
|
||||||
|
create_cmd_line_string() {
|
||||||
|
local arg
|
||||||
|
local -a allargs=()
|
||||||
|
local chars='[ !"#$&()*,;<>?\^`{|}]'
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
if [[ $1 == *\'* ]]; then
|
||||||
|
arg=\""$1"\"
|
||||||
|
elif [[ $1 == *$chars* ]]; then
|
||||||
|
arg="'$1'"
|
||||||
|
else
|
||||||
|
arg="$1"
|
||||||
|
fi
|
||||||
|
allargs+=("$arg") # ${allargs[@]} is to be used only for printing
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
printf '%s\n' "${allargs[*]}"
|
||||||
|
}
|
||||||
|
|
||||||
parse_cmd_line() {
|
parse_cmd_line() {
|
||||||
|
CMDLINE="$(create_cmd_line_string "${CMDLINE_ARRAY[@]}")"
|
||||||
|
|
||||||
# Show usage if no options were specified
|
# Show usage if no options were specified
|
||||||
[[ -z "$1" ]] && help 0
|
[[ -z "$1" ]] && help 0
|
||||||
# Set defaults if only an URI was specified, maybe ToDo: use "="-option, then: ${i#*=} i.e. substring removal
|
# Set defaults if only an URI was specified, maybe ToDo: use "="-option, then: ${i#*=} i.e. substring removal
|
||||||
|
|
Loading…
Reference in New Issue