[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
func_quote_for_eval and sed_quote_subst
From: |
Noah Misch |
Subject: |
func_quote_for_eval and sed_quote_subst |
Date: |
Sat, 16 Oct 2004 12:49:37 -0700 |
User-agent: |
Mutt/1.5.6i |
The name func_quote_for_eval brings to my mind this invariant:
Given any $foo, $bar and $foo compare identically after these commands:
func_quote_for_eval "$foo"
eval "bar=$func_quote_for_eval_result"
It is not so for $foo containing metacharacters with meaning within double
quotes. Naturally, then, $foo and $bar compare identically after these
command:
foo_subst=`echo "X$foo" | $Xsed -e "$sed_quote_subst"`
func_quote_for_eval "$foo_subst"
eval "bar=$func_quote_for_eval_result"
Perusing ltmain.m4sh, I see that a sed_quote_subst precedes most calls to
func_quote_for_eval. Does there exist a func_quote_for_eval on an argument that
we correctly do not filter through sed_quote_subst? If not, should
func_quote_for_eval actually do the sed_quote_subst?
One a related point, why
sed_quote_subst='s/\([\\`\\"$\\\\]\)/\\\1/g'
instead of this?
sed_quote_subst='s/\([`"$\]\)/\\\1/g'
As best I can tell, the extra backslashes in the former do not quote anything;
they just add more literal backslashes to the character class.
Here's a sample (untested) patch implementing the sed_quote_subst out-factoring:
--- config/general.m4sh.~1.4.~ 2004-10-08 13:01:49.000000000 -0400
+++ config/general.m4sh 2004-10-16 15:16:50.840649600 -0400
@@ -252,7 +252,7 @@ func_mktempdir ()
# Aesthetically quote ARG to be evaled later.
func_quote_for_eval ()
{
- my_arg="$1"
+ my_arg=`$ECHO "X$1" | $Xsed -e "$sed_quote_subst"`
case $my_arg in
# Double-quote args containing other shell metacharacters.
--- config/ltmain.m4sh.~1.11.~ 2004-10-16 11:02:05.000000000 -0400
+++ config/ltmain.m4sh 2004-10-16 15:30:23.198763200 -0400
@@ -1090,7 +1090,6 @@ func_mode_compile ()
esac # case $arg_mode
# Aesthetically quote the previous argument.
- lastarg=`$ECHO "X$lastarg" | $Xsed -e "$sed_quote_subst"`
func_quote_for_eval "$lastarg"
base_compile="$base_compile $func_quote_for_eval_result"
done # for arg
@@ -1511,8 +1510,8 @@ func_mode_execute ()
;;
esac
# Quote arguments (to preserve shell metacharacters).
- file=`$ECHO "X$file" | $Xsed -e "$sed_quote_subst"`
- args="$args \"$file\""
+ func_quote_for_eval "$file"
+ args="$args $func_quote_for_eval_result"
done
if test -z "$run"; then
@@ -1637,7 +1636,6 @@ func_mode_install ()
# Allow the use of GNU shtool's install command.
$ECHO "X$nonopt" | $Xsed | $GREP shtool > /dev/null; then
# Aesthetically quote it.
- arg=`$ECHO "X$nonopt" | $Xsed -e "$sed_quote_subst"`
func_quote_for_eval "$arg"
install_prog="$func_quote_for_eval_result "
arg="$1"
@@ -1649,7 +1647,6 @@ func_mode_install ()
# The real first argument should be the name of the installation program.
# Aesthetically quote it.
- arg=`$ECHO "X$arg" | $Xsed -e "$sed_quote_subst"`
func_quote_for_eval "$arg"
install_prog="$install_prog$func_quote_for_eval_result"
@@ -1693,7 +1690,6 @@ func_mode_install ()
esac
# Aesthetically quote the argument.
- arg=`$ECHO "X$arg" | $Xsed -e "$sed_quote_subst"`
func_quote_for_eval "$arg"
install_prog="$install_prog $func_quote_for_eval_result"
done
@@ -2198,7 +2194,6 @@ func_mode_link ()
while test "$#" -gt 0; do
arg="$1"
shift
- qarg=`$ECHO "X$arg" | $Xsed -e "$sed_quote_subst"`
func_quote_for_eval "$qarg"
libtool_args="$libtool_args $func_quote_for_eval_result"
@@ -2716,7 +2711,7 @@ func_mode_link ()
;;
-Wc,*)
- args=`$ECHO "X$arg" | $Xsed -e "$sed_quote_subst" -e 's/^-Wc,//'`
+ args=`$ECHO "X$arg" | $Xsed -e 's/^-Wc,//'`
arg=
save_ifs="$IFS"; IFS=','
for flag in $args; do
@@ -2730,7 +2725,7 @@ func_mode_link ()
;;
-Wl,*)
- args=`$ECHO "X$arg" | $Xsed -e "$sed_quote_subst" -e 's/^-Wl,//'`
+ args=`$ECHO "X$arg" | $Xsed -e s/^-Wl,//'`
arg=
save_ifs="$IFS"; IFS=','
for flag in $args; do
@@ -2765,7 +2760,6 @@ func_mode_link ()
# -q* pass through compiler args for the IBM compiler
# -m* pass through architecture-specific compiler args for GCC
-64|-mips[[0-9]]|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*)
- arg=`$ECHO "X$arg" | $Xsed -e "$sed_quote_subst"`
func_quote_for_eval "$arg"
arg="$func_quote_for_eval_result"
compile_command="$compile_command $arg"
@@ -2776,7 +2770,6 @@ func_mode_link ()
# Some other compiler flag.
-* | +*)
- arg=`$ECHO "X$arg" | $Xsed -e "$sed_quote_subst"`
func_quote_for_eval "$arg"
arg="$func_quote_for_eval_result"
;;
@@ -2910,7 +2903,6 @@ func_mode_link ()
*)
# Unknown arguments in both finalize_command and compile_command need
# to be aesthetically quoted because they are evaled later.
- arg=`$ECHO "X$arg" | $Xsed -e "$sed_quote_subst"`
func_quote_for_eval "$arg"
arg="$func_quote_for_eval_result"
;;
@@ -5593,8 +5585,8 @@ EOF
elif eval var_value=\$$var; test -z "$var_value"; then
relink_command="$var=; export $var; $relink_command"
else
- var_value=`$ECHO "X$var_value" | $Xsed -e "$sed_quote_subst"`
- relink_command="$var=\"$var_value\"; export $var; $relink_command"
+ func_quote_for_eval "$var_value"
+ relink_command="$var=$func_quote_for_eval_result; export $var;
$relink_command"
fi
done
relink_command="(cd `pwd`; $relink_command)"
@@ -6283,8 +6275,8 @@ fi\
elif eval var_value=\$$var; test -z "$var_value"; then
relink_command="$var=; export $var; $relink_command"
else
- var_value=`$ECHO "X$var_value" | $Xsed -e "$sed_quote_subst"`
- relink_command="$var=\"$var_value\"; export $var; $relink_command"
+ func_quote_for_eval "$var_value"
+ relink_command="$var=$func_quote_for_eval_result; export $var;
$relink_command"
fi
done
# Quote the link command for shipping.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- func_quote_for_eval and sed_quote_subst,
Noah Misch <=