Re: bash is hurling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



i beg to differ. every version of linux i have running (a couple of dozen),
with vintages spanning 1998 to 2020, prints the filename if given, as
a second word. on my own panix account it does this too:

   wc -l /etc/passwd

produces:

       1775 /etc/passwd

only if no filename is specified does a single word result:

   cat /etc/passwd | wc -l

produces:

       1775

there is a variation in padding of spaces in front of the first word (the
number of lines counted), but there are always two words as in the
example from the OP. no doubt that's what caused the reported error.

On Wed, Feb 17, 2021 at 11:38:16AM -0500, Linux for blind general discussion wrote:
> wc -l only returns one number.
> 
> 
> On Wed, 17 Feb 2021, Linux for blind general discussion wrote:
> 
> >the "wc" command is returning more than one word, is the problem with 
> >"let".
> >you don't need the "let" anyway, so:
> >
> >  cj=`wc -l chk-jenux.log`
> >
> >would be enough. but if you want only the count of lines, you either have 
> >to
> >1: isolate the first word from "wc" (the line count):
> >
> >  realcj=${cj%% *}
> >
> >or
> >2: do the "wc" without a file name:
> >
> >  cj=`cat chk-jenux.log | wc -l`
> >
> >note that the first example has a few failure modes, although there are 
> >endless
> >other ways to isolate a given word from a multi-word string. i've always
> >used the second example.
> >
> >On Tue, Feb 16, 2021 at 11:08:58AM -0500, Linux for blind general 
> >discussion wrote:
> >>I think I need a better shell.
> >>I wanted to get a line count into a variable and bash doesn't like what
> >>I'm doing to make that happen.  The code is:
> >>let "cj=`wc -l chk-jenux.log`"
> >

-- 
Henry Yen                                       Aegis Information Systems, Inc.
Senior Systems Programmer                       Hicksville, New York

_______________________________________________
Blinux-list mailing list
Blinux-list@xxxxxxxxxx
https://listman.redhat.com/mailman/listinfo/blinux-list




[Index of Archives]     [Linux Speakup]     [Fedora]     [Linux Kernel]     [Yosemite News]     [Big List of Linux Books]