bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Backslashed space in variable/argument expansion does not prevent sp


From: Greg Wooledge
Subject: Re: Backslashed space in variable/argument expansion does not prevent splitting.
Date: Fri, 17 Jun 2016 11:45:54 -0400
User-agent: Mutt/1.4.2.3i

On Fri, Jun 17, 2016 at 11:21:42AM +0100, Dean Wakerley wrote:
>  I ran into this problem when trying to buiild a TCL extension. Building
>  the extension requires pulling in    with source tclConfig.sh which
>  provides various settings. TCL_DEFS contains space separated -D
>  arguments    to pass to gcc. Some of these arguements contains space
>  which are backslashed to prevent splitting.

I've never seen a Tcl extension that requires sourcing a .sh file.
Granted, the Tcl extension space is a royal mess, but *sane* ones
are supposed to follow a standard known as TEA which is basically GNU
autoconf.

I'm guessing you're stuck with an insane one.  It would help to know
which one it is.  Maybe you're simply doing something wrong.

> # TCL_DEFS is actually source-d from TCL config script so have no
> # control over it.
>  TCL_DEFS='-DPACKAGE_NAME=\"tcl\" -DPACKAGE_TARNAME=\"tcl\" -
>  DPACKAGE_VERSION=\"8.5\" -DPACKAGE_STRING=\"tcl\ 8.5\" -
>  DPACKAGE_BUGREPORT=\"\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -

What you have here is from a file that is installed as part of Tcl
itself.  I have no idea why your extension thinks you should be sourcing
this file, or what it wants you to do with it.

> ./echo_args.sh ${TCL_DEFS}

I have my own args program.  This is what mine shows, if I pass it an
unquoted $TCL_DEFS to perform the word-splitting that you seem to want:

wooledg@wooledg:~$ source /opt/ebase/lib/tclConfig.sh 
wooledg@wooledg:~$ args $TCL_DEFS
64 args: <-DPACKAGE_NAME=\"tcl\"> <-DPACKAGE_TARNAME=\"tcl\"> 
<-DPACKAGE_VERSION=\"8.6\"> <-DPACKAGE_STRING=\"tcl\> <8.6\"> [[...]]

I've snipped it, because it's quite long.

Now bear in mind, these are not the ACTUAL arguments you would want
to pass to gcc.  These are options that have been spelled out with extra
backslashes in them because they are meant to be dropped into a Makefile,
or some other shell environment.  The shell environment will strip out
the backslashes as it interprets the command.

See how -DPACKAGE_STRING (fourth and fifth args) has been split into
two words.  This is because TCL_DEFS is NOT actually an array of arguments
that you can pass directly to a program.  It's a single string that has to
be copied out, into a Makefile, or a shell script, and then interpreted.

In other words, this will not work:

$ gcc $TCL_DEFS

It needs to be this:

$ eval gcc "$TCL_DEFS"

Here's what that looks like, using my args prorgam:

wooledg@wooledg:~$ eval args gcc "$TCL_DEFS"
63 args: <gcc> <-DPACKAGE_NAME="tcl"> <-DPACKAGE_TARNAME="tcl"> 
<-DPACKAGE_VERSION="8.6"> <-DPACKAGE_STRING="tcl 8.6"> [[...]]

Again, I've snipped it.

Either your Tcl extension's documentation is incorrect, or you are doing
something wrong.  That's all I can come up with.  There is no bash bug
here.

You might be better served by asking for help on this extension's
mailing list, if it has one.  If it doesn't (wouldn't be a surprise),
then on a general Tcl mailing list or newsgroup.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]