[comp.unix.questions] How to place a comma in 'a{b,c,d}e' metanotation

rouben@math9.math.umbc.edu (01/25/91)

The csh man page explains how the metanotation "a{b,c,d}e" expands into
"abe ace ade".  What it does not explain is how to place commas in the
output, if necessary.  For instance I wish that the construction
"a{b\,,c\,,d}" would expand to the comma separated list "ab, ac, ad",
but it actually expands to "ab a ac a ad".  I guess I do not know how
to escape the ',' character in these constructions.  Does anyone know how?

PS: This question came up when I wanted to extend the font path directory
of my X server.  The command I wanted to execute was:
	xset fp+ /path/dir1, /path/dir2, /path/dir3

so ideally I would have liked to say:

	xset fp+ /path/{dir1\,,dir2\,,dir3}

which does not work because the commas are not escaped correctly.
--
Rouben Rostamian                          Telephone: (301) 455-2458
Department of Mathematics and Statistics  e-mail:
University of Maryland Baltimore County   bitnet: rostamian@umbc.bitnet
Baltimore, MD 21228,  U.S.A.              internet: rouben@math9.math.umbc.edu

pfalstad@burst.Princeton.EDU (Paul Falstad) (01/25/91)

rouben@math9.math.umbc.edu () wrote:
>The csh man page explains how the metanotation "a{b,c,d}e" expands into
>"abe ace ade".  What it does not explain is how to place commas in the
>output, if necessary.  For instance I wish that the construction
>"a{b\,,c\,,d}" would expand to the comma separated list "ab, ac, ad",
>but it actually expands to "ab a ac a ad".  I guess I do not know how
>to escape the ',' character in these constructions.  Does anyone know how?

Apparently this is a bug in some versions of csh.  Our version (SunOS)
appears to have it fixed, but our version of tcsh (we don't have SunOS
source for csh) does not.  Apparently it can be fixed simply by
commenting out this line in sh.glob.c:

	case ','|QUOTE:

This is line 350 in my version of tcsh.  (Just grep for ','|QUOTE,
there's only one line remotely like that.)

Unless I'm stupid, there's no reason for that line to be there.  The
code looks like:

	case ','|QUOTE:
	case ',':
		... do the brace expansion ...

It looks like the author(s) went to extra effort to make , unquoteable.
Am I missing something or is it just a mistake?

--
Paul Falstad, pfalstad@phoenix.princeton.edu PLink:HYPNOS GEnie:P.FALSTAD
"And she's always on about men following her.  I don't know what she
thinks they're going to do to her.  Vomit on her, Basil, says."-Flowery Twats

clark@cme.nist.gov (Steve Clark) (01/25/91)

>>>>> On 24 Jan 91 17:29:18 GMT, rouben@math9.math.umbc.edu said:

rouben> <Asks how to get commas into the expansion of a{b,c,d}e?>

The problem (apparently) is that the shell handles escapes (and
variable substitutions, unfortunately) before expanding these lists.
If any escapes or variables produce commas, they will be interpreted
as separators between the braces.  So you need to force the shell to
expand the braces before the commas show up.  I don't see a solution
with escapes: the comma would still have to be there right from the
start.  Instead, I'd use a variable (to hold the comma until the
appropriate time) with eval (to stick in the comma(s) after the braces
are expanded).

rouben> ... ideally I would have liked to say:
rouben> 	xset fp+ /path/{dir1\,,dir2\,,dir3}

		% set c=,
		% xset fp+ `eval echo /path/{dir1\$c,dir2\$c,dir3}`

Which is only slightly longer :-) than the resulting command:

rouben> 	xset fp+ /path/dir1, /path/dir2, /path/dir3
--
-steve
------------------------------------------------------------------
Steve Clark
National Institute for Standards and Technology (formerly NBS)
clark@cme.nist.gov		..uunet!cme-durer!clark
(301)975-3595 / 3544

brnstnd@kramden.acf.nyu.edu (Dan Bernstein) (01/25/91)

If you want to quote the comma, quote the comma.

  % echo a{b,c,d,','}e
  abe ace ade a,e

> 	xset fp+ /path/{dir1\,,dir2\,,dir3}

  % echo /path/dir{1',',2',',3}
  /path/dir1, /path/dir2, /path/dir3

Disclaimer: This is probably portable but I don't know that it is.

---Dan

raja@bombay.cps.msu.edu (Narayan S. Raja) (01/25/91)

In article <4890@umbc3.UMBC.EDU>, Rouben Rostamian writes:

< The csh man page explains how the metanotation "a{b,c,d}e" expands into
< "abe ace ade".  What it does not explain is how to place commas in the
< output, if necessary.  For instance I wish that the construction
< "a{b\,,c\,,d}" would expand to the comma separated list "ab, ac, ad",


23 pixel>echo a{"b,","c,",d}
ab, ac, ad


Narayan Sriranga Raja.

subbarao@phoenix.Princeton.EDU (Kartik Subbarao) (01/25/91)

In article <20630:Jan2421:21:3091@kramden.acf.nyu.edu> brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes:
>If you want to quote the comma, quote the comma.
>
>  % echo a{b,c,d,','}e
>  abe ace ade a,e
>> 	xset fp+ /path/{dir1\,,dir2\,,dir3}
>
>  % echo /path/dir{1',',2',',3}
>  /path/dir1, /path/dir2, /path/dir3
>
>Disclaimer: This is probably portable but I don't know that it is.

Nope: Doesn't work on NeXT Mach 2.0.


			-Kartik

--
internet# find . -name core -exec cat {} \; |& tee /dev/tty*
subbarao@{phoenix or gauguin}.Princeton.EDU -|Internet
kartik@silvertone.Princeton.EDU (NeXT mail)       -|	
SUBBARAO@PUCC.BITNET			          - Bitnet

terryl@sail.LABS.TEK.COM (01/25/91)

In article <20630:Jan2421:21:3091@kramden.acf.nyu.edu> brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes:
>If you want to quote the comma, quote the comma.
>
>  % echo a{b,c,d,','}e
>  abe ace ade a,e


     OK, here goes on MY system:

% echo a{b,c,d,','}e
abe ace ade ae ae

>> 	xset fp+ /path/{dir1\,,dir2\,,dir3}
>
>  % echo /path/dir{1',',2',',3}
>  /path/dir1, /path/dir2, /path/dir3
>Disclaimer: This is probably portable but I don't know that it is.

      Portable if the bug which was previously described if fixed. I looked at
our C-shell sources, and it had the bug in it.....

__________________________________________________________
Terry Laskodi		"There's a permanent crease
     of			 in your right and wrong."
Tektronix		Sly and the Family Stone, "Stand!"
__________________________________________________________