Re: remove empty '' in ${var@Q} result?

2023-08-23 Thread Chet Ramey

On 8/20/23 12:20 PM, Clark Wang wrote:


I did. It's on the list of possible things for the next version. Since it's
only a cosmetic issue, it's not a high priority.


Hi Chet,

Is it possible to fix this in 5.3?


It's not a bug, and it's not a high priority.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/




Re: remove empty '' in ${var@Q} result?

2023-08-20 Thread Clark Wang
On Wed, Nov 8, 2017 at 9:46 PM Chet Ramey  wrote:

> On 11/7/17 11:38 PM, Clark Wang wrote:
>
> > I made a patch (also attached). Please see if it's ok.
> >
> >
> > Updated by dealing with empty strings (and malloc'ing 2 more bytes)
> > though I'm not sure if it's necessary since the func
> > sh_quote_reusable() already handles empty strings.
> >
> >
> > Hi Chet, do you have a look at my patch?
>
> I did. It's on the list of possible things for the next version. Since it's
> only a cosmetic issue, it's not a high priority.
>

Hi Chet,

Is it possible to fix this in 5.3?


Re: remove empty '' in ${var@Q} result?

2018-12-03 Thread Chet Ramey
On 11/28/18 9:58 PM, Clark Wang wrote:
> On Wed, Nov 8, 2017 at 9:46 PM Chet Ramey  > wrote:
> 
> On 11/7/17 11:38 PM, Clark Wang wrote:
> 
> >         I made a patch (also attached). Please see if it's ok.
> >
> >
> >     Updated by dealing with empty strings (and malloc'ing 2 more bytes)
> >     though I'm not sure if it's necessary since the func
> >     sh_quote_reusable() already handles empty strings.
> >
> >
> > Hi Chet, do you have a look at my patch?
> 
> I did. It's on the list of possible things for the next version. Since 
> it's
> only a cosmetic issue, it's not a high priority.
> 
> 
> Hi Chet,
> 
> Is it possible to make the change in the coming 5.0 release?

I am not making changes for bash-5.0 at this point, only bug fixes.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/



Re: remove empty '' in ${var@Q} result?

2018-11-28 Thread Clark Wang
On Wed, Nov 8, 2017 at 9:46 PM Chet Ramey  wrote:

> On 11/7/17 11:38 PM, Clark Wang wrote:
>
> > I made a patch (also attached). Please see if it's ok.
> >
> >
> > Updated by dealing with empty strings (and malloc'ing 2 more bytes)
> > though I'm not sure if it's necessary since the func
> > sh_quote_reusable() already handles empty strings.
> >
> >
> > Hi Chet, do you have a look at my patch?
>
> I did. It's on the list of possible things for the next version. Since it's
> only a cosmetic issue, it's not a high priority.
>

Hi Chet,

Is it possible to make the change in the coming 5.0 release?

-clark


Re: remove empty '' in ${var@Q} result?

2017-11-08 Thread Chet Ramey
On 11/7/17 11:38 PM, Clark Wang wrote:

> I made a patch (also attached). Please see if it's ok.
> 
> 
> Updated by dealing with empty strings (and malloc'ing 2 more bytes)
> though I'm not sure if it's necessary since the func
> sh_quote_reusable() already handles empty strings.
> 
> 
> Hi Chet, do you have a look at my patch?

I did. It's on the list of possible things for the next version. Since it's
only a cosmetic issue, it's not a high priority.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: remove empty '' in ${var@Q} result?

2017-11-07 Thread Clark Wang
On Tue, Oct 31, 2017 at 3:53 PM, Clark Wang  wrote:

> On Tue, Oct 31, 2017 at 3:25 PM, Clark Wang  wrote:
>
>> On Mon, Oct 30, 2017 at 10:41 PM, Chet Ramey  wrote:
>>
>>>
>>> This is an effect of using single quotes in the @Q operator. If you want
>>> to single-quote a string containing single quotes, this is how you do it.
>>>
>>
>> I made a patch (also attached). Please see if it's ok.
>>
>
> Updated by dealing with empty strings (and malloc'ing 2 more bytes) though
> I'm not sure if it's necessary since the func sh_quote_reusable() already
> handles empty strings.
>

Hi Chet, do you have a look at my patch?


Re: remove empty '' in ${var@Q} result?

2017-11-07 Thread Clark Wang
On Mon, Oct 30, 2017 at 8:35 PM, Greg Wooledge  wrote:

>
> What's the bug?  They are equivalent.
>

It's not a bad thing if we can make the language a bit more elegant unless
the cost is not worth it.

>
> If you mean "I would like bash to perform a second optimization pass
> over the result of ${var@Q} so that it's prettier in my degenerate edge
> cases", I suspect there are better uses of Chet's time, but it's his call.
>

It's not necessarily to perform a second pass parsing.

-clark


Re: remove empty '' in ${var@Q} result?

2017-10-31 Thread Clark Wang
On Tue, Oct 31, 2017 at 3:25 PM, Clark Wang  wrote:

> On Mon, Oct 30, 2017 at 10:41 PM, Chet Ramey  wrote:
>
>>
>> This is an effect of using single quotes in the @Q operator. If you want
>> to single-quote a string containing single quotes, this is how you do it.
>>
>
> I made a patch (also attached). Please see if it's ok.
>

Updated by dealing with empty strings (and malloc'ing 2 more bytes) though
I'm not sure if it's necessary since the func sh_quote_reusable() already
handles empty strings.


sh_single_quote.patch
Description: Binary data


Re: remove empty '' in ${var@Q} result?

2017-10-31 Thread Clark Wang
On Mon, Oct 30, 2017 at 10:41 PM, Chet Ramey  wrote:

>
> This is an effect of using single quotes in the @Q operator. If you want
> to single-quote a string containing single quotes, this is how you do it.
>

I made a patch (also attached). Please see if it's ok.

Tested with arr=('' a \' \'\' \'\'\' \'a a\' \'a\'a). the result will be:

arr[0]=''
arr[1]='a'
arr[2]=\'
arr[3]=\'\'
arr[4]=\'\'\'
arr[5]=\''a'
arr[6]='a'\'
arr[7]=\''a'\''a'

--- a/lib/sh/shquote.c
+++ b/lib/sh/shquote.c
@@ -98,34 +98,32 @@ sh_single_quote (string)
   register int c;
   char *result, *r;
   const char *s;
+  int left_quote_inserted = 0;

-  result = (char *)xmalloc (3 + (4 * strlen (string)));
+  result = (char *)xmalloc (1 + (3 * strlen (string)));
   r = result;

-  if (string[0] == '\'' && string[1] == 0)
-{
-  *r++ = '\\';
-  *r++ = '\'';
-  *r++ = 0;
-  return result;
-}
-
-  *r++ = '\'';
-
   for (s = string; s && (c = *s); s++)
 {
-  *r++ = c;
-
-  if (c == '\'')
-   {
- *r++ = '\\';  /* insert escaped single quote */
+  if (c == '\'') {
+   if (left_quote_inserted) {
+ *r++ = '\'';
+ left_quote_inserted = 0;
+   }
+   *r++ = '\\';
+   *r++ = '\'';
+  } else {
+   if ( ! left_quote_inserted) {
  *r++ = '\'';
- *r++ = '\'';  /* start new quoted string */
+ left_quote_inserted = 1;
}
+   *r++ = c;
+  }
 }
-
-  *r++ = '\'';
-  *r = '\0';
+  if (left_quote_inserted) {
+*r++ = '\'';
+  }
+  *r++ = 0;

   return (result);
 }


sh_single_quote.patch
Description: Binary data


Re: remove empty '' in ${var@Q} result?

2017-10-30 Thread Chet Ramey
On 10/29/17 10:34 PM, Clark Wang wrote:
> See following example:
> 
> [STEP 100] # echo $BASH_VERSION
> 4.4.12(2)-release
> [STEP 101] # v=\'\'
> [STEP 102] # printf '%q\n' "$v"
> \'\'
> [STEP 103] # printf '%s\n' "${v@Q}"
> ''\'''\'''
> [STEP 104] #

This is an effect of using single quotes in the @Q operator. If you want
to single-quote a string containing single quotes, this is how you do it.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: remove empty '' in ${var@Q} result?

2017-10-30 Thread Greg Wooledge
On Mon, Oct 30, 2017 at 10:34:47AM +0800, Clark Wang wrote:
> See following example:
> 
> [STEP 100] # echo $BASH_VERSION
> 4.4.12(2)-release
> [STEP 101] # v=\'\'
> [STEP 102] # printf '%q\n' "$v"
> \'\'
> [STEP 103] # printf '%s\n' "${v@Q}"
> ''\'''\'''
> [STEP 104] #

What's the bug?  They are equivalent.

If you mean "I would like bash to perform a second optimization pass
over the result of ${var@Q} so that it's prettier in my degenerate edge
cases", I suspect there are better uses of Chet's time, but it's his call.



remove empty '' in ${var@Q} result?

2017-10-29 Thread Clark Wang
See following example:

[STEP 100] # echo $BASH_VERSION
4.4.12(2)-release
[STEP 101] # v=\'\'
[STEP 102] # printf '%q\n' "$v"
\'\'
[STEP 103] # printf '%s\n' "${v@Q}"
''\'''\'''
[STEP 104] #