Merge sh-not-bash-bug-1035260

This commit is contained in:
Daniel Nichter
2012-08-24 11:43:05 -06:00
6 changed files with 102 additions and 87 deletions

View File

@@ -119,19 +119,22 @@ usage_or_errors() {
echo
echo "Options and values after processing arguments:"
echo
for opt in $(ls "$PO_DIR"); do
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
local varvalue="${!varname}"
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
if [ "$varvalue" -a "$varvalue" = "yes" ];
then varvalue="TRUE"
else
varvalue="FALSE"
(
cd "$PO_DIR"
for opt in *; do
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
eval local varvalue=\$$varname
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
if [ "$varvalue" -a "$varvalue" = "yes" ];
then varvalue="TRUE"
else
varvalue="FALSE"
fi
fi
fi
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
echo
done
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
echo
done
)
return 1
fi
@@ -191,7 +194,7 @@ parse_options() {
_parse_config_files "/etc/percona-toolkit/percona-toolkit.conf" "/etc/percona-toolkit/$TOOL.conf" "$HOME/.percona-toolkit.conf" "$HOME/.$TOOL.conf"
fi
_parse_command_line "$@"
_parse_command_line "${@:-""}"
}
_parse_pod() {
@@ -283,7 +286,7 @@ _eval_po() {
_parse_config_files() {
for config_file in "$@"; do
for config_file in "${@:-""}"; do
test -f "$config_file" || continue
while read config_opt; do
@@ -317,7 +320,7 @@ _parse_command_line() {
local required_arg=""
local spec=""
for opt in "$@"; do
for opt in "${@:-""}"; do
if [ "$opt" = "--" -o "$opt" = "----" ]; then
HAVE_EXT_ARGV=1
continue

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh
# This program is part of Percona Toolkit: http://www.percona.com/software/
# See "COPYRIGHT, LICENSE, AND WARRANTY" at the end of this file for legal
@@ -121,19 +121,22 @@ usage_or_errors() {
echo
echo "Options and values after processing arguments:"
echo
for opt in $(ls "$PO_DIR"); do
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
local varvalue="${!varname}"
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
if [ "$varvalue" -a "$varvalue" = "yes" ];
then varvalue="TRUE"
else
varvalue="FALSE"
(
cd "$PO_DIR"
for opt in *; do
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
eval local varvalue=\$$varname
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
if [ "$varvalue" -a "$varvalue" = "yes" ];
then varvalue="TRUE"
else
varvalue="FALSE"
fi
fi
fi
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
echo
done
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
echo
done
)
return 1
fi
@@ -193,7 +196,7 @@ parse_options() {
_parse_config_files "/etc/percona-toolkit/percona-toolkit.conf" "/etc/percona-toolkit/$TOOL.conf" "$HOME/.percona-toolkit.conf" "$HOME/.$TOOL.conf"
fi
_parse_command_line "$@"
_parse_command_line "${@:-""}"
}
_parse_pod() {
@@ -285,7 +288,7 @@ _eval_po() {
_parse_config_files() {
for config_file in "$@"; do
for config_file in "${@:-""}"; do
test -f "$config_file" || continue
while read config_opt; do
@@ -319,7 +322,7 @@ _parse_command_line() {
local required_arg=""
local spec=""
for opt in "$@"; do
for opt in "${@:-""}"; do
if [ "$opt" = "--" -o "$opt" = "----" ]; then
HAVE_EXT_ARGV=1
continue
@@ -608,7 +611,7 @@ shorten() {
}
group_concat () {
sed -e '{H; $!d;}' -e 'x' -e 's/\n[[:space:]]*\([[:digit:]]*\)[[:space:]]*/, \1x/g' -e 's/[[:space:]][[:space:]]*/ /g' -e 's/, //' "${1}"
sed -e 'H; $!d;' -e 'x' -e 's/\n[[:space:]]*\([[:digit:]]*\)[[:space:]]*/, \1x/g' -e 's/[[:space:]][[:space:]]*/ /g' -e 's/, //' "${1}"
}
# ###########################################################################
@@ -2314,7 +2317,7 @@ if [ "${0##*/}" = "$TOOL" ] \
# Set up temporary dir.
mk_tmpdir
# Parse command line options.
parse_options "$0" "$@"
parse_options "$0" "${@:-""}"
# Verify that --sleep, if present, is positive
if [ -n "$OPT_SLEEP" ] && [ "$OPT_SLEEP" -lt 0 ]; then
@@ -2335,7 +2338,7 @@ if [ "${0##*/}" = "$TOOL" ] \
# a connection then.
[ "$OPT_READ_SAMPLES" ] || check_mysql
main "$@"
main "${@:-""}"
fi
# ############################################################################

View File

@@ -588,7 +588,7 @@ main() {
# possible to include without executing, and thus test.
if [ "${0##*/}" = "$TOOL" ] \
|| [ "${0##*/}" = "bash" -a "$_" = "$0" ]; then
main "$@"
main "${@:-""}"
fi
# ############################################################################

View File

@@ -121,19 +121,22 @@ usage_or_errors() {
echo
echo "Options and values after processing arguments:"
echo
for opt in $(ls "$PO_DIR"); do
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
local varvalue="${!varname}"
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
if [ "$varvalue" -a "$varvalue" = "yes" ];
then varvalue="TRUE"
else
varvalue="FALSE"
(
cd "$PO_DIR"
for opt in *; do
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
eval local varvalue=\$$varname
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
if [ "$varvalue" -a "$varvalue" = "yes" ];
then varvalue="TRUE"
else
varvalue="FALSE"
fi
fi
fi
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
echo
done
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
echo
done
)
return 1
fi
@@ -193,7 +196,7 @@ parse_options() {
_parse_config_files "/etc/percona-toolkit/percona-toolkit.conf" "/etc/percona-toolkit/$TOOL.conf" "$HOME/.percona-toolkit.conf" "$HOME/.$TOOL.conf"
fi
_parse_command_line "$@"
_parse_command_line "${@:-""}"
}
_parse_pod() {
@@ -285,7 +288,7 @@ _eval_po() {
_parse_config_files() {
for config_file in "$@"; do
for config_file in "${@:-""}"; do
test -f "$config_file" || continue
while read config_opt; do
@@ -319,7 +322,7 @@ _parse_command_line() {
local required_arg=""
local spec=""
for opt in "$@"; do
for opt in "${@:-""}"; do
if [ "$opt" = "--" -o "$opt" = "----" ]; then
HAVE_EXT_ARGV=1
continue
@@ -1197,7 +1200,7 @@ if [ "${0##*/}" = "$TOOL" ] \
# Parse command line options. We must do this first so we can
# see if --daemonize was specified.
mk_tmpdir
parse_options "$0" "$@"
parse_options "$0" "${@:-""}"
# Verify and set TRIGGER_FUNCTION based on --function.
if ! set_trg_func "$OPT_FUNCTION"; then
@@ -1264,7 +1267,7 @@ if [ "${0##*/}" = "$TOOL" ] \
# the child's PID.
make_pid_file "$OPT_PID" $$
main "$@" </dev/null 1>>"$OPT_LOG" 2>&1 &
main "${@:-""}" </dev/null 1>>"$OPT_LOG" 2>&1 &
# Update PID file with the child's PID.
# The child PID is $BASHPID but that special var is only
@@ -1273,7 +1276,7 @@ if [ "${0##*/}" = "$TOOL" ] \
echo "$!" > "$OPT_PID"
else
[ "$OPT_STALK" ] && make_pid_file "$OPT_PID" $$
main "$@"
main "${@:-""}"
fi
fi

View File

@@ -128,19 +128,22 @@ usage_or_errors() {
echo
echo "Options and values after processing arguments:"
echo
for opt in $(ls "$PO_DIR"); do
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
local varvalue="${!varname}"
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
if [ "$varvalue" -a "$varvalue" = "yes" ];
then varvalue="TRUE"
else
varvalue="FALSE"
(
cd "$PO_DIR"
for opt in *; do
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
eval local varvalue=\$$varname
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
if [ "$varvalue" -a "$varvalue" = "yes" ];
then varvalue="TRUE"
else
varvalue="FALSE"
fi
fi
fi
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
echo
done
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
echo
done
)
return 1
fi
@@ -200,7 +203,7 @@ parse_options() {
_parse_config_files "/etc/percona-toolkit/percona-toolkit.conf" "/etc/percona-toolkit/$TOOL.conf" "$HOME/.percona-toolkit.conf" "$HOME/.$TOOL.conf"
fi
_parse_command_line "$@"
_parse_command_line "${@:-""}"
}
_parse_pod() {
@@ -292,7 +295,7 @@ _eval_po() {
_parse_config_files() {
for config_file in "$@"; do
for config_file in "${@:-""}"; do
test -f "$config_file" || continue
while read config_opt; do
@@ -326,7 +329,7 @@ _parse_command_line() {
local required_arg=""
local spec=""
for opt in "$@"; do
for opt in "${@:-""}"; do
if [ "$opt" = "--" -o "$opt" = "----" ]; then
HAVE_EXT_ARGV=1
continue
@@ -2186,7 +2189,7 @@ if [ "${0##*/}" = "$TOOL" ] \
# Set up temporary dir.
mk_tmpdir
# Parse command line options.
parse_options "$0" "$@"
parse_options "$0" "${@:-""}"
usage_or_errors "$0"
po_status=$?
rm_tmpdir
@@ -2195,7 +2198,7 @@ if [ "${0##*/}" = "$TOOL" ] \
exit $po_status
fi
main "$@"
main "${@:-""}"
fi

View File

@@ -118,21 +118,24 @@ usage_or_errors() {
echo
echo "Options and values after processing arguments:"
echo
for opt in $(ls "$PO_DIR"); do
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
local varvalue="${!varname}"
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
# Typeless option, like --version, so it's given/TRUE
# or not given/FALSE.
if [ "$varvalue" -a "$varvalue" = "yes" ];
then varvalue="TRUE"
else
varvalue="FALSE"
(
cd "$PO_DIR"
for opt in *; do
local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)"
eval local varvalue=\$$varname
if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then
# Typeless option, like --version, so it's given/TRUE
# or not given/FALSE.
if [ "$varvalue" -a "$varvalue" = "yes" ];
then varvalue="TRUE"
else
varvalue="FALSE"
fi
fi
fi
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
echo
done
printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}"
echo
done
)
return 1
fi
@@ -213,7 +216,7 @@ parse_options() {
fi
# Finally, parse the command line.
_parse_command_line "$@"
_parse_command_line "${@:-""}"
}
_parse_pod() {
@@ -318,7 +321,7 @@ _eval_po() {
_parse_config_files() {
for config_file in "$@"; do
for config_file in "${@:-""}"; do
# Next config file if this one doesn't exist.
test -f "$config_file" || continue
@@ -377,7 +380,7 @@ _parse_command_line() {
local required_arg=""
local spec=""
for opt in "$@"; do
for opt in "${@:-""}"; do
if [ "$opt" = "--" -o "$opt" = "----" ]; then
HAVE_EXT_ARGV=1
continue