bash is hurling

Linux for blind general discussion blinux-list at redhat.com
Thu Feb 18 04:48:36 UTC 2021


I managed to use cut in the pipe to extract the number to a variable.
Maybe tomorrow I figure out my logic error further down in the script but 
the calculator is low on coffee and I need sleep so will get sleep and 
coffee in that order before trying to tackle this one.



On Wed, 17 Feb 2021, Linux for blind general discussion wrote:

> 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`"
>>>
>
>




More information about the Blinux-list mailing list