zsh-users
 help / color / mirror / code / Atom feed
* triviality regarding $# counts
@ 2024-04-11  0:56 Ray Andrews
  2024-04-12  4:55 ` Lawrence Velázquez
  0 siblings, 1 reply; 40+ messages in thread
From: Ray Andrews @ 2024-04-11  0:56 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 2568 bytes --]

This practice text is in a variable 'temp' and I want to count the 
number of lines inside a function that will also print the text exactly 
as shown, and do a bunch of other stuff.

--------------------------------------------------------------------
xz-utils:
/usr/bin/xzgrep
/usr/share/man  /de/man1/xzgrep.1.gz    # Hafta be careful not to split 
here.
/usr/share/man  /ko/man1/xzgrep.1.gz    # ... or here.
/usr/share/man/man1/xzgrep.1.gz
/usr/share/man/pt_BR/man1/xzgrep.1.gz
/usr/share/man/ro/man1/xzgrep.1.gz
/usr/share/man/uk/man1/xzgrep.1.gz
/usr/bin/xzegrep
/usr/bin/xzfgrep
/usr/share/man/de/man1/lzegrep.1.gz
/usr/share/man/de/man1/lzfgrep.1.gz
/usr/share/man/uk/man1/xzegrep.1.gz
/usr/share/man/uk/man1/xzfgrep.1.gz

zsh-common:
/usr/share/doc/zsh-common/examples/Functions/zpgrep
/usr/share/zsh/functions/Completion/Debian/_grep-excuses
/usr/share/zsh/functions/Completion/Unix/_grep
/usr/share/zsh/functions/Completion/Unix/_ngrep
/usr/share/zsh/functions/Completion/Unix/_pgrep

zstd:
/usr/bin/zstdgrep
/usr/share/man/man1/zstdgrep.1.gz
-----------------------------------------------------------------------------------

This works: (Again, this is deep in a function and I have to use eval.)

     output=$( eval "$@" )   # '$@' will expand to 'print -l $temp' 
which is the text above.
     temp=( $( eval $@ ) )    # To get the correct count I need to force 
an array.
     linecount=$#temp
     print -rl -- $output
     print  $linecount

Various experiments trying to get the correct linecount (23) *and* get 
it printing correctly all end up with waterboarding problems. If I do it 
in two stages as above, it's ok, but is seems very clumsy.  Different 
efforts at quoting or using ' ${(@f) ....} ' and various other tricks 
yield me a linecount of 1, 3, 23, 25, 26, or 738.  And output that 
deletes the blank lines, or forces everything into one 'line/element'.  
Basically I need the array form to to get the line count, but it won't 
print properly as an array.  Not that it's worth much trouble, but is it 
possible to get the variable  to print correctly *and* show the count of 
lines without having to eval it twice?  schematically:

     output=????$( eval ???)??? # Whatever the correct code might be.
     linecount=$#output
     print -rl -- $output
     print  $linecount

... as it is, it seems that '$#' never counts the lines of output as it 
actually prints.  In practice it's hardly a problem but still it bothers 
me.  '$#' seems mostly to want to count characters (738).



[-- Attachment #2: Type: text/html, Size: 3390 bytes --]

^ permalink raw reply	[flat|nested] 40+ messages in thread

end of thread, other threads:[~2024-04-14 22:01 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-11  0:56 triviality regarding $# counts Ray Andrews
2024-04-12  4:55 ` Lawrence Velázquez
2024-04-12 14:48   ` Ray Andrews
2024-04-12 19:09     ` Bart Schaefer
2024-04-13  1:13       ` Ray Andrews
2024-04-13  1:33         ` Mark J. Reed
2024-04-13  2:28           ` Ray Andrews
2024-04-13  3:25             ` Lawrence Velázquez
2024-04-13 14:37               ` Ray Andrews
2024-04-13 15:14                 ` Ray Andrews
2024-04-13 17:19                   ` Mark J. Reed
2024-04-13 17:27                     ` Mark J. Reed
2024-04-13 18:08                       ` Ray Andrews
2024-04-13 19:45                         ` Bart Schaefer
2024-04-13 20:36                           ` Ray Andrews
2024-04-13 21:01                             ` Bart Schaefer
2024-04-14  0:28                               ` Ray Andrews
2024-04-14  0:30                               ` Lawrence Velázquez
2024-04-14  3:26                                 ` Ray Andrews
2024-04-14  3:49                                   ` Lawrence Velázquez
2024-04-14  4:57                                     ` Bart Schaefer
2024-04-14 13:24                                       ` Ray Andrews
2024-04-14 13:35                                         ` Roman Perepelitsa
2024-04-14 14:06                                           ` Ray Andrews
2024-04-14 14:15                                             ` Roman Perepelitsa
2024-04-14 14:53                                               ` Ray Andrews
2024-04-14 15:11                                                 ` Mark J. Reed
2024-04-14 16:23                                                   ` Ray Andrews
2024-04-14 14:06                                         ` Mark J. Reed
2024-04-14 14:47                                           ` Ray Andrews
2024-04-14 14:59                                             ` Mark J. Reed
2024-04-14 15:51                                         ` Bart Schaefer
2024-04-14 17:22                                           ` Ray Andrews
2024-04-14 17:42                                             ` Mark J. Reed
2024-04-14 18:24                                               ` Bart Schaefer
2024-04-14 22:00                                               ` Ray Andrews
2024-04-13 20:11                         ` Mark J. Reed
2024-04-13 20:53                   ` Bart Schaefer
2024-04-14  0:19                     ` Ray Andrews
2024-04-13  1:35         ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).