Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: double quoted expansion question

2012/9/7 Jérémie Roquet <arkanosis@xxxxxxxxx>:
> 2012/9/7 Sebastian Stark <seb-zsh@xxxxxxxxxxx>:
>> I am trying to make a unique list of tags that is given in a string with a certain format, e.  g.:
>>   servers="
>>   madeira linux,gpu,users
>>   madeira2 linux,gpu,users
>>   smtp linux,mail,smtp
>>   isar linux,users
>>   easygwa linux,web,external
>>   "
>> The format is: server name, space, tag, comma, tag, comma, tag ...
>> What I want from the above list is this:
>>   external gpu linux mail smtp users web
>> and I get it with:
>>   print  ${(s:,:uo)${(j:,:)${${(f)servers}//* /}}}
>> However, if I do this:
>>   print "${(s:,:uo)${(j:,:)${${(f)servers}//* /}}}"
>> I get:
>>   external linux web
>> This also happens when I use the variable expansion expression in a here document, which, I suppose, is undergoing the same treatment as double quoted strings.
>> What I would like to understand here is why the output changes the way it does when I add double quotes around my expression. I would expect the same output as without. If anybody could shed some light please, I guess it's just something obvious I cannot see.
> I'm not 100 % sure, but I suppose the quotes prevents the shell from
> splitting your string on $IFS, so you only have *one* string, and the
> “//* /" expression suppresses everything before the last space,
> leaving only the tags of the last line.

No, this has nothing to do with $IFS actually, but you still have one string:

$ a=(za zb zc zd)
$ echo ${a/z/v}
va vb vc vd
$ echo "${a/z/v}"
va zb zc zd


Messages sorted by: Reverse Date, Date, Thread, Author