Re: tcsh script: quote and spaces problems

2003-07-31 Thread Dan Nelson
In the last episode (Aug 01), Rob Lahaye said:
> Another odd behaviour occurs when I say:
> 
>   set foo="abc"
> 
> which tcsh reduces to "a b c", despite the quotes.

This works for me (-CURRENT).

$ tcsh
dan: {3001} set foo="abc"
dan: {3002} set | grep foo
_   set foo="abc"
foo abc
dan: {3003} echo "$foo"
abc
dan: {3004} 
 
-- 
Dan Nelson
[EMAIL PROTECTED]
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: tcsh script: quote and spaces problems

2003-07-31 Thread Rob Lahaye

Dan Nelson wrote:
> 
> Actually it doesn't.  You get this result because sh splits variables
> on $IFS before passing the result to a command, so what echo gets is
>  argv[1]="-f \"t"
>  argv[2]="\""

I come to the conclusion that there's no intuitive solution in a
tcsh script for

   set foo='-f "a  "'

My unix knowledge tells me the following should work:

   set foo="-f\ \"a\ \ \""

but tcsh does not allow these escape sequences; the backslashes
become real backslashes and an error occurs on too many
quotes.

Another odd behaviour occurs when I say:

  set foo="abc"

which tcsh reduces to "a b c", despite the quotes.


I'd say very un-unix like behaviours

Rob.

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: tcsh script: quote and spaces problems

2003-07-31 Thread Dan Nelson
In the last episode (Jul 31), Chuck Swiger said:
> Rob Lahaye wrote:
> [ ... ]
> >Any solutions for this problem with quotes and spaces in tcsh
> >script? Or is tcsh not suitable for this kind of things?
> 
> Ugh, the latter.  :-)  /bin/sh handles nested quoting right, but crunches 
> the space together:
> 
> % foo="-f \"t  \""
> % echo $foo
> -f "t "
> 
> % foo='-f "t  "'
> % echo $foo
> -f "t "

Actually it doesn't.  You get this result because sh splits variables
on $IFS before passing the result to a command, so what echo gets is
 argv[1]="-f \"t"
 argv[2]="\""
, and echo always prints its arguments separated by a space.  You can
verify that the variable is set correctly by running "set | grep -a
foo".  To pass the entire string as one argument, run echo "$foo".

> ...however, you might be able to muck with $IFS and get better results. 
> Also, ZSH seems to do exactly what you expected:
> 
> 64-sec% foo="-f \"t  \""
> 65-sec% echo $foo
> -f "t  "

This is because zsh passes variables directly to commands, unless the
SH_WORD_SPLIT flag is set.  You can force spltting with the ${=foo}
syntax.

-- 
Dan Nelson
[EMAIL PROTECTED]
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: tcsh script: quote and spaces problems

2003-07-31 Thread Michael E. Mercer
ok ok... I noticed one thing while playing with this...

the script hello.sh
#!/bin/tcsh -f

set JUNK='-f "t  "'

echo ">>${JUNK}<<"
echo ">>"${JUNK}"<<"

The first echo prints it -f "t  "
and the second -f "t "

Can you use it with the double quotes around it?

later
MeM


On Thu, 2003-07-31 at 22:12, Michael E. Mercer wrote:
> On Thu, 2003-07-31 at 21:42, Rob Lahaye wrote:
> > When I use
> >set flag='-f "t  "'
> > 
> 
> When I echo this out, I get what you are wanting...
> can you show us how you are using this, to get the "weird" behavior?
> 
> Thanks
> MeM
> 
> ___
> [EMAIL PROTECTED] mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "[EMAIL PROTECTED]"

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: tcsh script: quote and spaces problems

2003-07-31 Thread Chuck Swiger
Rob Lahaye wrote:
[ ... ]
Any solutions for this problem with quotes and spaces in tcsh script?
Or is tcsh not suitable for this kind of things?
Ugh, the latter.  :-)  /bin/sh handles nested quoting right, but crunches the 
space together:

% foo="-f \"t  \""
% echo $foo
-f "t "
% foo='-f "t  "'
% echo $foo
-f "t "
...however, you might be able to muck with $IFS and get better results. Also, 
ZSH seems to do exactly what you expected:

64-sec% foo="-f \"t  \""
65-sec% echo $foo
-f "t  "
67-sec% foo='-f "t  "'
68-sec% echo $foo
-f "t  "
--
-Chuck
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: tcsh script: quote and spaces problems

2003-07-31 Thread Michael E. Mercer
On Thu, 2003-07-31 at 21:42, Rob Lahaye wrote:
> When I use
>set flag='-f "t  "'
> 

When I echo this out, I get what you are wanting...
can you show us how you are using this, to get the "weird" behavior?

Thanks
MeM

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


tcsh script: quote and spaces problems

2003-07-31 Thread Rob Lahaye


Hello,

I've been trying to include the quote (") characters and spaces into a tcsh script
variable; for already two days I've been trying various ways doing this to no avail!
I'm about to think that it is impossible.
For example:


#!/bin/tcsh
set flag="-f "t  ""

This obviously doesn't work because of too many quotes involved; but what does work
to achieve this? There are two problems here:
  1) flag should contain the two internal quotes of "t  "
  2) the "t  " contains two spaces.
When I use
  set flag='-f "t  "'
the two spaces are automagically (?) reduced to only one space!!

The latter seems to be a general problem:

  set flag="f "

wil result in flag containing only "f ".

Any solutions for this problem with quotes and spaces in tcsh script?
Or is tcsh not suitable for this kind of things?
Thanks,
Rob.


___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"