On Mon, Sep 19, 2011 at 6:06 PM, Robert Shinka <k...@unknownlayer.net> wrote:
> On Mon, Sep 19, 2011 at 04:18:18PM +0300, Philip Ganchev wrote:
>> On Mon, Sep 19, 2011 at 1:47 AM, Robert Shinka <k...@unknownlayer.net> wrote:
>> > On Sun, Sep 18, 2011 at 09:20:21PM +0200, Jan Kanis wrote:
>>
>> >>  Bash treats command substitution and variable expansion as a list of
>> >>  whitespace separated tokens. It also includes escapes to treat both as a
>> >>  single token, in case you don't want the default behaviour.
>> >>
>> >>  Fish does the same for variables, except it doesn't split the contents 
>> >> when
>> >>  the variable is used, but it stores the tokens in a structured way as an
>> >>  array. Command substitution works a bit differently. Maintaining a 
>> >> structured
>> >>  form of data like with variables isn't possible because it is output from
>> >>  arbitrary commands, so fish splits the command output like bash does, 
>> >> but only
>> >>  on newlines. However fish doesn't provide a way to prevent the splitting.
>> >
>> > If fish reconstructed "$var" the same way it split it (with \n), then
>> > your problem wouldn't exist. You could work with lines as usual with
>> > $var, and "$var" would produce the exact data it was created with.
>> > If anyone needed a space-separated version of the string for whatever
>> > reason, they could trivially do so with echo or tr, but I think that's a
>> > rare case. Right now, there's no reasonable utility.
>>
>> Yes, that would be more logical. But separating with spaces saves
>> screen space when printing the array, which is quite a common
>> operation.
>
> I'm only proposing changing the semantics of "$var", while $var would be
> unchanged, so the common case of (echo $var) would format as usual,
> separated with spaces, but (echo "$var") would print the original
> string, including any embedded newlines.
>
> eg.,
>> set var (echo 1\n2\n3)
>> echo $var     # echo '1' '2' '3'
> 1 2 3
>> echo "$var"   # echo '1\n2\n3'
> 1
> 2
> 3
>
> Is there a compelling reason not to make this change?

Oh, I see. The only argument against that I can see is that it is an
extra syntax rule to remember.

This would solve Jan's use case by first setting a variable, as you
show above. But maybe it would be logical if process substitution has
a symmetric syntax:

echo (echo 1\n2\n3)
1 2 3
echo "(echo 1\n2\n3)"
1
2
3

Regards,
Philip

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to