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

Re: Printf builtin missing v flag support



On 01/01/2016 04:57 PM, Eric Cook wrote:
> On 12/31/2015 01:48 PM, Bart Schaefer wrote:
>> On Dec 31, 10:44am, Peter Stephenson wrote:
>> }
>> } The feature is obviously useful but the print implementation is
>> } a nightmare of special cases making it hard to change without
>> } considerable refactoring. That would probably be a Good Work, given
>> } enough test cases to check it, but is going to have to wait for a
>> } volunteer.
>> }
>> } I haven't checked whether -v is already in use in which case this is moot.
>>
>> -v is not in use, and the print implementation has already been refactored
>> to support the -z and -s options in printf, so this is actually rather
>> easy.
>>
>> I noticed that "print" uses metafy() on the aguments to -z and -s, but
>> "printf" did not, so I added metafy() for those cases.  Somebody holler
>> if this is wrong.
>>
>>
> 
> Could zsh error when an invalid parameter name is used?
> 
> % printf -v -- '%s' foo
> -v%
> % printf -v '%s' foo
> -v%
> % printf -v
> -v%
> 
> $ printf -v -- '%s' foo
> bash: printf: `--': not a valid identifier
> $ printf -v '%s' foo
> bash: printf: `%s': not a valid identifier
> $ printf -v
> bash: printf: -v: option requires an argument
> printf: usage: printf [-v var] format [arguments]
> 
> bash's printf -v can also assign to array elements, which isn't possible currently.
> 
> % typeset -A foo; printf -v 'foo[bar]' baz; typeset -p foo
> -vtypeset -A foo
> 
> % printf -v 'a[2+2]' foo; typeset -p a
> foo=( )
> 
> $ typeset -A foo; printf -v 'foo[bar]' baz; typeset -p foo
> declare -A foo='([bar]="baz" )'
> $ printf -v 'a[2+2]' foo; typeset -p a
> declare -a a='([4]="foo")'
> 
weeeeee, used the wrong version here, please ignore the email.



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