Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

<sangr> home is where the highest bandwidth is


devel / comp.unix.shell / How do you insert a newline using AWK?

SubjectAuthor
* How do you insert a newline using AWK?Chris Roberts
+- Re: How do you insert a newline using AWK?Lew Pitcher
+- Re: How do you insert a newline using AWK?Helmut Waitzmann
+* Re: How do you insert a newline using AWK?Janis Papanagnou
|+* Re: How do you insert a newline using AWK?Helmut Waitzmann
||`* Re: How do you insert a newline using AWK?Janis Papanagnou
|| `- Re: How do you insert a newline using AWK?Helmut Waitzmann
|`- Re: How do you insert a newline using AWK?Barry Margolin
`* Re: How do you insert a newline using AWK?Ed Morton
 +* Re: How do you insert a newline using AWK?Janis Papanagnou
 |+* Re: How do you insert a newline using AWK?Ed Morton
 ||+* Re: How do you insert a newline using AWK?Spiros Bousbouras
 |||+- Re: How do you insert a newline using AWK?Kenny McCormack
 |||`- Re: How do you insert a newline using AWK?Ed Morton
 ||`* Re: How do you insert a newline using AWK?Janis Papanagnou
 || `* Re: How do you insert a newline using AWK?Ed Morton
 ||  `* Re: How do you insert a newline using AWK?Janis Papanagnou
 ||   `* shellcheck (Was: How do you insert a newline using AWK?)Kenny McCormack
 ||    `* Re: shellcheck (Was: How do you insert a newline using AWK?)Janis Papanagnou
 ||     +* Re: shellcheck (Was: How do you insert a newline using AWK?)Ed Morton
 ||     |`* Re: shellcheck (Was: How do you insert a newline using AWK?)Janis Papanagnou
 ||     | `- shellcheck and embedded AWK scripts (Was: shellcheck (Was: How do you insert a nKenny McCormack
 ||     `- Re: shellcheck (Was: How do you insert a newline using AWK?)Janis Papanagnou
 |`- Re: How do you insert a newline using AWK?Janis Papanagnou
 `* Re: How do you insert a newline using AWK?Lew Pitcher
  `* Re: How do you insert a newline using AWK?Ed Morton
   `- Re: How do you insert a newline using AWK?Spiros Bousbouras

Pages:12
How do you insert a newline using AWK?

<fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3796&group=comp.unix.shell#3796

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a37:aa0b:: with SMTP id t11mr7442618qke.70.1621366408129;
Tue, 18 May 2021 12:33:28 -0700 (PDT)
X-Received: by 2002:ac8:4049:: with SMTP id j9mr6662975qtl.79.1621366407927;
Tue, 18 May 2021 12:33:27 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!2.eu.feeder.erje.net!feeder.erje.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Tue, 18 May 2021 12:33:27 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=4.79.195.162; posting-account=tSqayAoAAADEbq2bVxu4ODgY7tmW5dUx
NNTP-Posting-Host: 4.79.195.162
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com>
Subject: How do you insert a newline using AWK?
From: thecjg...@gmail.com (Chris Roberts)
Injection-Date: Tue, 18 May 2021 19:33:28 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Chris Roberts - Tue, 18 May 2021 19:33 UTC

Using AWK, I am unable to insert a newline "\n"
Nothing I try seems to work here.
Not sure why it makes it all into a single line like this.
Does anyone know of a simple way to fix this?
And/Or an explanation?

#ls -l
total 276
-rwxrwxrwx 1 crzzy1 crzzy1 211456 Sep 1 2020 NppToolBucket.dll
-rwxrwxrwx 1 crzzy1 crzzy1 212 Sep 3 2020 backup
-rwxrwxrwx 1 crzzy1 crzzy1 0 May 18 15:03 badip
-rwxrwxrwx 1 crzzy1 crzzy1 1399 May 11 11:53 ccc
-rwxrwxrwx 1 crzzy1 crzzy1 1622 Nov 2 2020 ccclab
-rwxrwxrwx 1 crzzy1 crzzy1 2217 May 7 13:09 cccp

#a=`ls -l | awk '{print $8"\n"}'
#echo $a
2020 2020 15:03 11:53 2020 13:09

Thanks
crzzy1

Re: How do you insert a newline using AWK?

<s816u9$t2k$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3798&group=comp.unix.shell#3798

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.shell
Subject: Re: How do you insert a newline using AWK?
Date: Tue, 18 May 2021 20:09:45 -0000 (UTC)
Organization: The Pitcher Digital Freehold
Lines: 49
Message-ID: <s816u9$t2k$1@dont-email.me>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 18 May 2021 20:09:45 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="a33a41c39cea386debd997886e9c6bf2";
logging-data="29780"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19rgN9jPL5X9FJEOi7Jz6DWAu9RCEXulug="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:sJ40Bx++qnyVWtxhgaKAzbr+p7I=
 by: Lew Pitcher - Tue, 18 May 2021 20:09 UTC

On Tue, 18 May 2021 12:33:27 -0700, Chris Roberts wrote:

> Using AWK, I am unable to insert a newline "\n"
> Nothing I try seems to work here.
> Not sure why it makes it all into a single line like this.
> Does anyone know of a simple way to fix this?
> And/Or an explanation?
>
> #ls -l
> total 276
> -rwxrwxrwx 1 crzzy1 crzzy1 211456 Sep 1 2020 NppToolBucket.dll
> -rwxrwxrwx 1 crzzy1 crzzy1 212 Sep 3 2020 backup
> -rwxrwxrwx 1 crzzy1 crzzy1 0 May 18 15:03 badip
> -rwxrwxrwx 1 crzzy1 crzzy1 1399 May 11 11:53 ccc
> -rwxrwxrwx 1 crzzy1 crzzy1 1622 Nov 2 2020 ccclab
> -rwxrwxrwx 1 crzzy1 crzzy1 2217 May 7 13:09 cccp
>
> #a=`ls -l | awk '{print $8"\n"}'

Here's a hint: try testing in parts

1) You know what output
ls -l
will give you (see above), so find out what output
ls -l | awk '{print $8"\n"}'
will give you. I bet that it /won't/ be the output
that you expect.

2) try to find out what the backtick operator does
to output. You know that
ls -l
outputs lines, so what does
a=`ls -l`
echo $a
give you? Hint: bash(1) "Command Substitution"

> #echo $a
> 2020 2020 15:03 11:53 2020 13:09

That result is not unexpected, given your use of backticks and echo

>
> Thanks
> crzzy1

HTH
--
Lew Pitcher
"In Skills, We Trust"

Re: How do you insert a newline using AWK?

<83v97f23m0.fsf@helmutwaitzmann.news.arcor.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3800&group=comp.unix.shell#3800

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!wZqT5cURFqiI3zWJtYOD9A.user.gioia.aioe.org.POSTED!not-for-mail
From: nn.throt...@xoxy.net (Helmut Waitzmann)
Newsgroups: comp.unix.shell
Subject: Re: How do you insert a newline using AWK?
Date: Tue, 18 May 2021 22:23:19 +0200
Organization: Aioe.org NNTP Server
Lines: 52
Message-ID: <83v97f23m0.fsf@helmutwaitzmann.news.arcor.de>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com>
Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
NNTP-Posting-Host: wZqT5cURFqiI3zWJtYOD9A.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Complaints-To: abuse@aioe.org
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)
Cancel-Lock: sha1:U7cuJ/pID3OxlyDJYwCNzUPtyVM=
Mail-Copies-To: nobody
X-Notice: Filtered by postfilter v. 0.9.2
Mail-Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
 by: Helmut Waitzmann - Tue, 18 May 2021 20:23 UTC

Chris Roberts <thecjguy1@gmail.com>:

>Using AWK, I am unable to insert a newline "\n"
>Nothing I try seems to work here.
>Not sure why it makes it all into a single line like this.
>Does anyone know of a simple way to fix this?
>And/Or an explanation?
>
> #ls -l
>total 276
>-rwxrwxrwx 1 crzzy1 crzzy1 211456 Sep 1 2020 NppToolBucket.dll
>-rwxrwxrwx 1 crzzy1 crzzy1 212 Sep 3 2020 backup
>-rwxrwxrwx 1 crzzy1 crzzy1 0 May 18 15:03 badip
>-rwxrwxrwx 1 crzzy1 crzzy1 1399 May 11 11:53 ccc
>-rwxrwxrwx 1 crzzy1 crzzy1 1622 Nov 2 2020 ccclab
>-rwxrwxrwx 1 crzzy1 crzzy1 2217 May 7 13:09 cccp
>
>#a=`ls -l | awk '{print $8"\n"}'
>#echo $a
>2020 2020 15:03 11:53 2020 13:09

Try

echo "$a"

rather than

echo $a

>Not sure why it makes it all into a single line like this.
>

The unquoted shell parameter (here: variable) expansion is the
culprit. 

>Does anyone know of a simple way to fix this?
>

Use quoted parameter expansion. 

>And/Or an explanation?
>

Unquoted parameter expansions suffer from field splitting
(<https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05>). 

As a rule of thumb:  In the shell's command line, always use quoted
rather than unquoted parameter expansions (unless you want those
strange effects with unquoted parameter expansions to happen). 

Re: How do you insert a newline using AWK?

<s82jpo$d7u$1@news-1.m-online.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3801&group=comp.unix.shell#3801

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: How do you insert a newline using AWK?
Date: Wed, 19 May 2021 10:55:20 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 47
Message-ID: <s82jpo$d7u$1@news-1.m-online.net>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com>
NNTP-Posting-Host: 2001:a61:252a:da01:806c:bdd5:1857:99d0
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1621414520 13566 2001:a61:252a:da01:806c:bdd5:1857:99d0 (19 May 2021 08:55:20 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Wed, 19 May 2021 08:55:20 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
X-Enigmail-Draft-Status: N1110
In-Reply-To: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com>
 by: Janis Papanagnou - Wed, 19 May 2021 08:55 UTC

On 18.05.2021 21:33, Chris Roberts wrote:
> Using AWK, I am unable to insert a newline "\n"
> Nothing I try seems to work here.
> Not sure why it makes it all into a single line like this.
> Does anyone know of a simple way to fix this?
> And/Or an explanation?

The command substitution `...` or the equivalent but better $(...)
does that; it connects all the parts in one line, separated by the
field separator, and leading/trailing whitespace truncated.

I suppose you don't want another newline (awk's print does that
already for you) but want to have these data unmodified, one entry
per line. If so you can do that by disabling the IFS variable for
the command

IFS= a=`ls -l | awk '{print $8}'`

IFS= a=$(ls -l | awk '{print $8}')

To suppress the empty line from the ls header do

IFS= a=$(ls -l | awk 'NR>1 {print $8}')

Janis

> #ls -l
> total 276
> -rwxrwxrwx 1 crzzy1 crzzy1 211456 Sep 1 2020 NppToolBucket.dll
> -rwxrwxrwx 1 crzzy1 crzzy1 212 Sep 3 2020 backup
> -rwxrwxrwx 1 crzzy1 crzzy1 0 May 18 15:03 badip
> -rwxrwxrwx 1 crzzy1 crzzy1 1399 May 11 11:53 ccc
> -rwxrwxrwx 1 crzzy1 crzzy1 1622 Nov 2 2020 ccclab
> -rwxrwxrwx 1 crzzy1 crzzy1 2217 May 7 13:09 cccp
>
> #a=`ls -l | awk '{print $8"\n"}'
> #echo $a
> 2020 2020 15:03 11:53 2020 13:09
>
>
> Thanks
> crzzy1
>
>
>

Re: How do you insert a newline using AWK?

<838s4b12bo.fsf@helmutwaitzmann.news.arcor.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3802&group=comp.unix.shell#3802

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!E9So4KdIRu983BxldZxngA.user.gioia.aioe.org.POSTED!not-for-mail
From: nn.throt...@xoxy.net (Helmut Waitzmann)
Newsgroups: comp.unix.shell
Subject: Re: How do you insert a newline using AWK?
Date: Wed, 19 May 2021 11:48:43 +0200
Organization: Aioe.org NNTP Server
Lines: 29
Message-ID: <838s4b12bo.fsf@helmutwaitzmann.news.arcor.de>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com>
<s82jpo$d7u$1@news-1.m-online.net>
Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
NNTP-Posting-Host: E9So4KdIRu983BxldZxngA.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Complaints-To: abuse@aioe.org
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)
Mail-Copies-To: nobody
Cancel-Lock: sha1:e7HaKqRWYptS+sBUf3L3HsCZnpg=
Mail-Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
X-Notice: Filtered by postfilter v. 0.9.2
 by: Helmut Waitzmann - Wed, 19 May 2021 09:48 UTC

Janis Papanagnou <janis_papanagnou@hotmail.com>:
>On 18.05.2021 21:33, Chris Roberts wrote:

>> Using AWK, I am unable to insert a newline "\n"
>> Nothing I try seems to work here.
>> Not sure why it makes it all into a single line like this.
>> Does anyone know of a simple way to fix this?
>> And/Or an explanation?
>
>The command substitution `...` or the equivalent but better $(...)
>does that; it connects all the parts in one line, separated by the
>field separator, and leading/trailing whitespace truncated.

I don't think so.  Try

( a=$( printf '%s\n' 1 2 3 ) && echo "$a" )

>I suppose you don't want another newline (awk's print does that
>already for you) but want to have these data unmodified, one entry
>per line. If so you can do that by disabling the IFS variable for
>the command

I don't think so either.  Try

( IFS= a=$( printf '%s\n' 1 2 3 ) && echo $a )

Re: How do you insert a newline using AWK?

<s82pag$enk$1@news-1.m-online.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3803&group=comp.unix.shell#3803

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!news.mixmin.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: How do you insert a newline using AWK?
Date: Wed, 19 May 2021 12:29:36 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 49
Message-ID: <s82pag$enk$1@news-1.m-online.net>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com>
<s82jpo$d7u$1@news-1.m-online.net>
<838s4b12bo.fsf@helmutwaitzmann.news.arcor.de>
NNTP-Posting-Host: 2001:a61:252a:da01:806c:bdd5:1857:99d0
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1621420176 15092 2001:a61:252a:da01:806c:bdd5:1857:99d0 (19 May 2021 10:29:36 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Wed, 19 May 2021 10:29:36 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
X-Enigmail-Draft-Status: N1110
In-Reply-To: <838s4b12bo.fsf@helmutwaitzmann.news.arcor.de>
 by: Janis Papanagnou - Wed, 19 May 2021 10:29 UTC

On 19.05.2021 11:48, Helmut Waitzmann wrote:
> Janis Papanagnou <janis_papanagnou@hotmail.com>:
>> On 18.05.2021 21:33, Chris Roberts wrote:
>
>>> Using AWK, I am unable to insert a newline "\n"
>>> Nothing I try seems to work here.
>>> Not sure why it makes it all into a single line like this.
>>> Does anyone know of a simple way to fix this?
>>> And/Or an explanation?
>>
>> The command substitution `...` or the equivalent but better $(...)
>> does that; it connects all the parts in one line, separated by the
>> field separator, and leading/trailing whitespace truncated.
>
>
> I don't think so. Try
>
> ( a=$( printf '%s\n' 1 2 3 ) && echo "$a" )

You are right. The assignment is an internal command and needs
no quoting. The effect is visible with an unquoted variable or
if the command is unquoted like echo $( printf '%s\n' 1 2 3 )
where a quoted command echo "$( printf '%s\n' 1 2 3 )" works
fine as well.

Setting IFS= also works fine it seems...

>> I suppose you don't want another newline (awk's print does that
>> already for you) but want to have these data unmodified, one entry per
>> line. If so you can do that by disabling the IFS variable for the command
>
>
> I don't think so either. Try
>
> ( IFS= a=$( printf '%s\n' 1 2 3 ) && echo $a )

$ ( a=$( printf '%s\n' 1 2 3 ) && echo $a )
1 2 3

$ ( IFS= a=$( printf '%s\n' 1 2 3 ) && echo $a )
1 2
3

Please explain your thought.

Janis

Re: How do you insert a newline using AWK?

<barmar-ABE12F.15421419052021@reader.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3805&group=comp.unix.shell#3805

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!barmar.motzarella.org!.POSTED!not-for-mail
From: bar...@alum.mit.edu (Barry Margolin)
Newsgroups: comp.unix.shell
Subject: Re: How do you insert a newline using AWK?
Date: Wed, 19 May 2021 15:42:15 -0400
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <barmar-ABE12F.15421419052021@reader.eternal-september.org>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com> <s82jpo$d7u$1@news-1.m-online.net>
Injection-Info: barmar.motzarella.org; posting-host="39229b344c962f4b4b1404a55ab14ec8";
logging-data="31925"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18WWJ4RjbBCCmFt4iuFwlwy"
User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)
Cancel-Lock: sha1:Kidt/A4NaMXSPSuYWnRtfItR/P4=
 by: Barry Margolin - Wed, 19 May 2021 19:42 UTC

In article <s82jpo$d7u$1@news-1.m-online.net>,
Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:

> On 18.05.2021 21:33, Chris Roberts wrote:
> > Using AWK, I am unable to insert a newline "\n"
> > Nothing I try seems to work here.
> > Not sure why it makes it all into a single line like this.
> > Does anyone know of a simple way to fix this?
> > And/Or an explanation?
>
> The command substitution `...` or the equivalent but better $(...)
> does that; it connects all the parts in one line, separated by the
> field separator, and leading/trailing whitespace truncated.

You're right that it's command substitution doing it, but you have some
details wrong.

It just removes any trailing newlines. Not leading whitespace, and not
any other trailing whitespace.

However,

echo $a

performs word splitting, so all leading and trailing whitespaces are
discarded, and embedded sequences of whitespace are merged into a single
word delimiter. This is why variables should generally be quoted:

echo "$a"

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Re: How do you insert a newline using AWK?

<83sg2izaw7.fsf@helmutwaitzmann.news.arcor.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3806&group=comp.unix.shell#3806

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!NRXqxbh/bxEpo88iUp1yxA.user.gioia.aioe.org.POSTED!not-for-mail
From: nn.throt...@xoxy.net (Helmut Waitzmann)
Newsgroups: comp.unix.shell
Subject: Re: How do you insert a newline using AWK?
Date: Wed, 19 May 2021 23:11:52 +0200
Organization: Aioe.org NNTP Server
Lines: 88
Message-ID: <83sg2izaw7.fsf@helmutwaitzmann.news.arcor.de>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com>
<s82jpo$d7u$1@news-1.m-online.net>
<838s4b12bo.fsf@helmutwaitzmann.news.arcor.de>
<s82pag$enk$1@news-1.m-online.net>
Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
NNTP-Posting-Host: NRXqxbh/bxEpo88iUp1yxA.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Complaints-To: abuse@aioe.org
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)
X-Notice: Filtered by postfilter v. 0.9.2
Mail-Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
Cancel-Lock: sha1:pJzEG4QispJutnvIqDd5J0eZk1o=
Mail-Copies-To: nobody
 by: Helmut Waitzmann - Wed, 19 May 2021 21:11 UTC

Janis Papanagnou <janis_papanagnou@hotmail.com>:
>On 19.05.2021 11:48, Helmut Waitzmann wrote:
>> Janis Papanagnou <janis_papanagnou@hotmail.com>:

>>> The command substitution `...` or the equivalent but better $(...)
>>> does that; it connects all the parts in one line, separated by the
>>> field separator, and leading/trailing whitespace truncated.
>>
>>
>> I don't think so. Try
>>
>>
>> ( a=$( printf '%s\n' 1 2 3 ) && echo "$a" )
>
>You are right. The assignment is an internal command and needs
>no quoting. The effect is visible with an unquoted variable or
>if the command is unquoted like echo $( printf '%s\n' 1 2 3 )
>where a quoted command echo "$( printf '%s\n' 1 2 3 )" works
>fine as well.
>
>Setting IFS= also works fine it seems...
>
>
>>> I suppose you don't want another newline (awk's print does that
>>> already for you) but want to have these data unmodified, one
>>> entry per line. If so you can do that by disabling the IFS
>>> variable for the command
>>
>>
>> I don't think so either. Try
>>
>>
>> ( IFS= a=$( printf '%s\n' 1 2 3 ) && echo $a )
>
>
>$ ( a=$( printf '%s\n' 1 2 3 ) && echo $a )
>1 2 3
>
>$ ( IFS= a=$( printf '%s\n' 1 2 3 ) && echo $a )
>1
>2
>3
>
>Please explain your thought.
>

I'm sorry, because I showed the wrong command.  I meant to write

(
set_or_unset_var()
{
# Set or unset a variable the name of which is given as
# the first positional parameter. The second parameter
# if given will be used to set the variable. If there
# is no second parameter then the variable will be unset.

: "${1:?'missing variable name'}" &&
eval "$1"'=${2-}' &&
${2+:} eval 'unset -v -- '"$1"
} &&

# Save the variable 'IFS' into the variable 'saved_IFS':
#
set_or_unset_var saved_IFS ${IFS+"${IFS}"} &&

# Then empty the variable 'IFS' and assign two and a
# half line to the variable 'a':
#
IFS= &&
a=$( printf '%s\n' 1 2 3 ) &&

# Restore the original value of the variable 'IFS'
#
set_or_unset_var IFS ${saved_IFS+"$saved_IFS"} &&

echo $a
)

It will output

1 2 3

even though the variable 'IFS' was empty at the time of the
assignment to the variable 'a'.  The expansion of the variable 'a'
will suffer from field splitting when 'IFS' has been reset.

Re: How do you insert a newline using AWK?

<s85u54$48l$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3807&group=comp.unix.shell#3807

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: mortons...@gmail.com (Ed Morton)
Newsgroups: comp.unix.shell
Subject: Re: How do you insert a newline using AWK?
Date: Thu, 20 May 2021 10:10:28 -0500
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <s85u54$48l$1@dont-email.me>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 20 May 2021 15:10:28 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5a6fed0c6727f4408ef4048ad3889946";
logging-data="4373"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/WOehr6160oj+WLKwE/RcG"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.10.2
Cancel-Lock: sha1:dqzNcgBCfZdayK8f1ukJ42E0cYY=
In-Reply-To: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com>
X-Antivirus-Status: Clean
Content-Language: en-US
X-Antivirus: Avast (VPS 210520-2, 05/20/2021), Outbound message
 by: Ed Morton - Thu, 20 May 2021 15:10 UTC

On 5/18/2021 2:33 PM, Chris Roberts wrote:
> Using AWK, I am unable to insert a newline "\n"
> Nothing I try seems to work here.
> Not sure why it makes it all into a single line like this.
> Does anyone know of a simple way to fix this?
> And/Or an explanation?
>
> #ls -l
> total 276
> -rwxrwxrwx 1 crzzy1 crzzy1 211456 Sep 1 2020 NppToolBucket.dll
> -rwxrwxrwx 1 crzzy1 crzzy1 212 Sep 3 2020 backup
> -rwxrwxrwx 1 crzzy1 crzzy1 0 May 18 15:03 badip
> -rwxrwxrwx 1 crzzy1 crzzy1 1399 May 11 11:53 ccc
> -rwxrwxrwx 1 crzzy1 crzzy1 1622 Nov 2 2020 ccclab
> -rwxrwxrwx 1 crzzy1 crzzy1 2217 May 7 13:09 cccp
>
> #a=`ls -l | awk '{print $8"\n"}'
> #echo $a
> 2020 2020 15:03 11:53 2020 13:09

Copy/paste your 2-line script into http://shellcheck.net and it'll tell
you what the problems are with it.

Ed.

Re: How do you insert a newline using AWK?

<s8605c$c82$1@news-1.m-online.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3808&group=comp.unix.shell#3808

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!news.mixmin.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: How do you insert a newline using AWK?
Date: Thu, 20 May 2021 17:44:44 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 37
Message-ID: <s8605c$c82$1@news-1.m-online.net>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com>
<s85u54$48l$1@dont-email.me>
NNTP-Posting-Host: 2001:a61:252a:da01:a0b0:fa49:6e9f:8369
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1621525484 12546 2001:a61:252a:da01:a0b0:fa49:6e9f:8369 (20 May 2021 15:44:44 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Thu, 20 May 2021 15:44:44 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
X-Enigmail-Draft-Status: N1110
In-Reply-To: <s85u54$48l$1@dont-email.me>
 by: Janis Papanagnou - Thu, 20 May 2021 15:44 UTC

On 20.05.2021 17:10, Ed Morton wrote:
> On 5/18/2021 2:33 PM, Chris Roberts wrote:
>> Using AWK, I am unable to insert a newline "\n"
>> Nothing I try seems to work here.
>> Not sure why it makes it all into a single line like this.
>> Does anyone know of a simple way to fix this?
>> And/Or an explanation?
>>
>> #ls -l
>> total 276
>> -rwxrwxrwx 1 crzzy1 crzzy1 211456 Sep 1 2020 NppToolBucket.dll
>> -rwxrwxrwx 1 crzzy1 crzzy1 212 Sep 3 2020 backup
>> -rwxrwxrwx 1 crzzy1 crzzy1 0 May 18 15:03 badip
>> -rwxrwxrwx 1 crzzy1 crzzy1 1399 May 11 11:53 ccc
>> -rwxrwxrwx 1 crzzy1 crzzy1 1622 Nov 2 2020 ccclab
>> -rwxrwxrwx 1 crzzy1 crzzy1 2217 May 7 13:09 cccp
>>
>> #a=`ls -l | awk '{print $8"\n"}'
>> #echo $a
>> 2020 2020 15:03 11:53 2020 13:09
>
> Copy/paste your 2-line script into http://shellcheck.net and it'll tell
> you what the problems are with it.

Isn't the shell-checker's suggestion:
"Use find instead of ls to better handle non-alphanumeric filenames."
rather strange (to say the least)?

(Shouldn't a shell-checker focus on the shell and not on used external
or compound commands? That it obviously cannot semantically grasp.)

Janis

>
> Ed.
>

Re: How do you insert a newline using AWK?

<s860p5$14s$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3809&group=comp.unix.shell#3809

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.shell
Subject: Re: How do you insert a newline using AWK?
Date: Thu, 20 May 2021 15:55:17 -0000 (UTC)
Organization: The Pitcher Digital Freehold
Lines: 57
Message-ID: <s860p5$14s$1@dont-email.me>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com>
<s85u54$48l$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 20 May 2021 15:55:17 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="2ed9f5a018ceca3485966d667516d869";
logging-data="1180"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+sz+uXCPoxx1YZZobDcTfMDT0tEETr2UA="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:hrT5ia0ODTISmiJqNVC+Pe8MrA4=
 by: Lew Pitcher - Thu, 20 May 2021 15:55 UTC

On Thu, 20 May 2021 10:10:28 -0500, Ed Morton wrote:

> On 5/18/2021 2:33 PM, Chris Roberts wrote:
>> Using AWK, I am unable to insert a newline "\n"
>> Nothing I try seems to work here.
>> Not sure why it makes it all into a single line like this.
>> Does anyone know of a simple way to fix this?
>> And/Or an explanation?
>>
>> #ls -l
>> total 276
>> -rwxrwxrwx 1 crzzy1 crzzy1 211456 Sep 1 2020 NppToolBucket.dll
>> -rwxrwxrwx 1 crzzy1 crzzy1 212 Sep 3 2020 backup
>> -rwxrwxrwx 1 crzzy1 crzzy1 0 May 18 15:03 badip
>> -rwxrwxrwx 1 crzzy1 crzzy1 1399 May 11 11:53 ccc
>> -rwxrwxrwx 1 crzzy1 crzzy1 1622 Nov 2 2020 ccclab
>> -rwxrwxrwx 1 crzzy1 crzzy1 2217 May 7 13:09 cccp
>>
>> #a=`ls -l | awk '{print $8"\n"}'
>> #echo $a
>> 2020 2020 15:03 11:53 2020 13:09
>
> Copy/paste your 2-line script into http://shellcheck.net and it'll tell
> you what the problems are with it.

Bench-check the script, and /learn/ what the problems are

* the awk print prints the requisite data, plus an extra blank
line because the OP included a "/n" in the print stream. Had
the OP coded that step as
awk '{print $8}'
each datum would print on it's own line, without additional blanks

* when using the backtick operator, trailing newlines are deleted but
embedded newlines aren't (although "they may be removed during word
splitting"), so
a=`ls -l | awk '{print $8"\n"}'
fills shell variable <<a>> with the doublespaced results, minus the
trailing newline(s)

* in the naked
echo $a
the shell variable <<a>> becomes a candidate for word splitting ("The
shell scans the results of parameter expansion, command substitution,
and arithmetic expansion that did not occur within double quotes for
word splitting"). the shell uses the value of the <<IFS>> shell variable
(or space, tab, and newline, if <<IFS>> is not set) to perform splitting,
and, thus, replaces the newlines with a single whitespace value. As this
echo did not doublequote it's argument, word splitting occurred, replacing
all embedded newline, tab and space sequences with single whitespace elements.

--
Lew Pitcher
"In Skills, We Trust"

Re: How do you insert a newline using AWK?

<s8633a$bqp$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3810&group=comp.unix.shell#3810

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: mortons...@gmail.com (Ed Morton)
Newsgroups: comp.unix.shell
Subject: Re: How do you insert a newline using AWK?
Date: Thu, 20 May 2021 11:34:49 -0500
Organization: A noiseless patient Spider
Lines: 123
Message-ID: <s8633a$bqp$1@dont-email.me>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com>
<s85u54$48l$1@dont-email.me> <s8605c$c82$1@news-1.m-online.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 20 May 2021 16:34:50 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5a6fed0c6727f4408ef4048ad3889946";
logging-data="12121"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19y/xtdhv2Lgr6cgD3Lj5pm"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.10.2
Cancel-Lock: sha1:fSYl1i98suCxmzD5GNSwU/gfJqU=
In-Reply-To: <s8605c$c82$1@news-1.m-online.net>
X-Antivirus-Status: Clean
Content-Language: en-US
X-Antivirus: Avast (VPS 210520-2, 05/20/2021), Outbound message
 by: Ed Morton - Thu, 20 May 2021 16:34 UTC

On 5/20/2021 10:44 AM, Janis Papanagnou wrote:
> On 20.05.2021 17:10, Ed Morton wrote:
>> On 5/18/2021 2:33 PM, Chris Roberts wrote:
>>> Using AWK, I am unable to insert a newline "\n"
>>> Nothing I try seems to work here.
>>> Not sure why it makes it all into a single line like this.
>>> Does anyone know of a simple way to fix this?
>>> And/Or an explanation?
>>>
>>> #ls -l
>>> total 276
>>> -rwxrwxrwx 1 crzzy1 crzzy1 211456 Sep 1 2020 NppToolBucket.dll
>>> -rwxrwxrwx 1 crzzy1 crzzy1 212 Sep 3 2020 backup
>>> -rwxrwxrwx 1 crzzy1 crzzy1 0 May 18 15:03 badip
>>> -rwxrwxrwx 1 crzzy1 crzzy1 1399 May 11 11:53 ccc
>>> -rwxrwxrwx 1 crzzy1 crzzy1 1622 Nov 2 2020 ccclab
>>> -rwxrwxrwx 1 crzzy1 crzzy1 2217 May 7 13:09 cccp
>>>
>>> #a=`ls -l | awk '{print $8"\n"}'
>>> #echo $a
>>> 2020 2020 15:03 11:53 2020 13:09
>>
>> Copy/paste your 2-line script into http://shellcheck.net and it'll tell
>> you what the problems are with it.
>
> Isn't the shell-checker's suggestion:
> "Use find instead of ls to better handle non-alphanumeric filenames."
> rather strange (to say the least)?
>
> (Shouldn't a shell-checker focus on the shell and not on used external
> or compound commands? That it obviously cannot semantically grasp.)

No, that's generally good advice, see https://mywiki.wooledge.org/ParsingLs.

The tool is just telling you about _potential_ issues, though, once you
understand the issue you can change the code as the tool suggests or add
a comment disabling the warning or just ignore it as you like.

That isn't all that shellcheck reports though.

Given the original 2-line script:

-----
a=`ls -l | awk '{print $8"\n"}'
echo $a
-----

shellcheck outputs:

-----
Line 1:
a=`ls -l | awk '{print $8"\n"}'
^-- SC1009: The mentioned syntax error was in this variable assignment.
^-- SC1073: Couldn't parse this backtick expansion. Fix to allow more
checks.

Line 2:
echo $a
^-- SC1072: Fix any mentioned problems and try again.
-----

When you fix that to get:

-----
a=`ls -l | awk '{print $8"\n"}'`
echo $a
-----

shellcheck outputs:

-----
Line 1:
a=`ls -l | awk '{print $8"\n"}'`
^-- SC2148: Tips depend on target shell and yours is unknown. Add a
shebang or a 'shell' directive.
^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
^-- SC2012: Use find instead of ls to better handle non-alphanumeric
filenames.

Did you mean: (apply this, apply all SC2006)
a=$(ls -l | awk '{print $8"\n"}')

Line 2:
echo $a
^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean: (apply this, apply all SC2086)
echo "$a"
-----

When you add a shebang to fix the first message:

-----
#!/usr/bin/env bash
a=`ls -l | awk '{print $8"\n"}'`
echo $a
-----

shellcheck outputs:

-----
Line 2:
a=`ls -l | awk '{print $8"\n"}'`
^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
^-- SC2012: Use find instead of ls to better handle non-alphanumeric
filenames.

Did you mean: (apply this, apply all SC2006)
a=$(ls -l | awk '{print $8"\n"}')

Line 3:
echo $a
^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean: (apply this, apply all SC2086)
echo "$a"
-----

Note that at this point shellcheck is telling you of 3 issues in the
script and of course that last one is the key to the problem the OP is
specifically asking about.

Ed.

Re: How do you insert a newline using AWK?

<s863d3$e2u$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3811&group=comp.unix.shell#3811

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: mortons...@gmail.com (Ed Morton)
Newsgroups: comp.unix.shell
Subject: Re: How do you insert a newline using AWK?
Date: Thu, 20 May 2021 11:40:03 -0500
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <s863d3$e2u$1@dont-email.me>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com>
<s85u54$48l$1@dont-email.me> <s860p5$14s$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 20 May 2021 16:40:03 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5a6fed0c6727f4408ef4048ad3889946";
logging-data="14430"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+0j0gPqVPdwhcjca+IJT+k"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.10.2
Cancel-Lock: sha1:sjHKThtxNvquXsXm0Mx2NYLMKh8=
In-Reply-To: <s860p5$14s$1@dont-email.me>
X-Antivirus-Status: Clean
Content-Language: en-US
X-Antivirus: Avast (VPS 210520-2, 05/20/2021), Outbound message
 by: Ed Morton - Thu, 20 May 2021 16:40 UTC

On 5/20/2021 10:55 AM, Lew Pitcher wrote:
> On Thu, 20 May 2021 10:10:28 -0500, Ed Morton wrote:
>
>> On 5/18/2021 2:33 PM, Chris Roberts wrote:
>>> Using AWK, I am unable to insert a newline "\n"
>>> Nothing I try seems to work here.
>>> Not sure why it makes it all into a single line like this.
>>> Does anyone know of a simple way to fix this?
>>> And/Or an explanation?
>>>
>>> #ls -l
>>> total 276
>>> -rwxrwxrwx 1 crzzy1 crzzy1 211456 Sep 1 2020 NppToolBucket.dll
>>> -rwxrwxrwx 1 crzzy1 crzzy1 212 Sep 3 2020 backup
>>> -rwxrwxrwx 1 crzzy1 crzzy1 0 May 18 15:03 badip
>>> -rwxrwxrwx 1 crzzy1 crzzy1 1399 May 11 11:53 ccc
>>> -rwxrwxrwx 1 crzzy1 crzzy1 1622 Nov 2 2020 ccclab
>>> -rwxrwxrwx 1 crzzy1 crzzy1 2217 May 7 13:09 cccp
>>>
>>> #a=`ls -l | awk '{print $8"\n"}'
>>> #echo $a
>>> 2020 2020 15:03 11:53 2020 13:09
>>
>> Copy/paste your 2-line script into http://shellcheck.net and it'll tell
>> you what the problems are with it.
>
> Bench-check the script, and /learn/ what the problems are
>
> * the awk print prints the requisite data, plus an extra blank
> line because the OP included a "/n" in the print stream. Had
> the OP coded that step as
> awk '{print $8}'
> each datum would print on it's own line, without additional blanks
>
> * when using the backtick operator, trailing newlines are deleted but
> embedded newlines aren't (although "they may be removed during word
> splitting"), so
> a=`ls -l | awk '{print $8"\n"}'
> fills shell variable <<a>> with the doublespaced results, minus the
> trailing newline(s)
>
> * in the naked
> echo $a
> the shell variable <<a>> becomes a candidate for word splitting ("The
> shell scans the results of parameter expansion, command substitution,
> and arithmetic expansion that did not occur within double quotes for
> word splitting"). the shell uses the value of the <<IFS>> shell variable
> (or space, tab, and newline, if <<IFS>> is not set) to perform splitting,
> and, thus, replaces the newlines with a single whitespace value. As this
> echo did not doublequote it's argument, word splitting occurred, replacing
> all embedded newline, tab and space sequences with single whitespace elements.

One of the nice things about running shellcheck is it gives you a link
to click on where you can find out more about each issue so not only do
we not have to identify the issues in the OPs code, we don't have to
explain them either. Just run the tool.... Not saying it'll
uncover/explain everything but it goes a long way for most common issues
and then we can help with any issues remaining after the code has been
cleaned up to the point of making shellcheck happy.

Ed.

Re: How do you insert a newline using AWK?

<yTadvYnmFtQZvSJlY@bongo-ra.co>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3812&group=comp.unix.shell#3812

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!news-out.netnews.com!newsin.alt.net!fdcspool1.netnews.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx09.ams4.POSTED!not-for-mail
From: spi...@gmail.com (Spiros Bousbouras)
Newsgroups: comp.unix.shell
Subject: Re: How do you insert a newline using AWK?
Message-ID: <yTadvYnmFtQZvSJlY@bongo-ra.co>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com> <s85u54$48l$1@dont-email.me> <s8605c$c82$1@news-1.m-online.net>
<s8633a$bqp$1@dont-email.me>
In-Reply-To: <s8633a$bqp$1@dont-email.me>
X-Organisation: Weyland-Yutani
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Lines: 129
X-Complaints-To: http://netreport.virginmedia.com
NNTP-Posting-Date: Thu, 20 May 2021 20:51:43 UTC
Organization: virginmedia.com
Date: Thu, 20 May 2021 20:51:43 GMT
X-Received-Bytes: 4710
 by: Spiros Bousbouras - Thu, 20 May 2021 20:51 UTC

On Thu, 20 May 2021 11:34:49 -0500
Ed Morton <mortonspam@gmail.com> wrote:
> On 5/20/2021 10:44 AM, Janis Papanagnou wrote:
> > On 20.05.2021 17:10, Ed Morton wrote:

[...]

> >> Copy/paste your 2-line script into http://shellcheck.net and it'll tell
> >> you what the problems are with it.

[...]

> The tool is just telling you about _potential_ issues, though, once you
> understand the issue you can change the code as the tool suggests or add
> a comment disabling the warning or just ignore it as you like.

Pretty much anything can count as a potential issue. To some people using the
shell at all as opposed to a "proper" language (like Perl or Python) is a
potential issue.

> That isn't all that shellcheck reports though.
>
> Given the original 2-line script:
>
> -----
> a=`ls -l | awk '{print $8"\n"}'
> echo $a
> -----
>
> shellcheck outputs:
>
> -----
> Line 1:
> a=`ls -l | awk '{print $8"\n"}'
> ^-- SC1009: The mentioned syntax error was in this variable assignment.
> ^-- SC1073: Couldn't parse this backtick expansion. Fix to allow more
> checks.

This is useful. But an even better advice is that people asking programming
questions should paste in their post the code which caused the question
instead of retyping it. I'm guessing that the opening poster didn't do this.

> Line 2:
> echo $a
> ^-- SC1072: Fix any mentioned problems and try again.
> -----
>
> When you fix that to get:
>
> -----
> a=`ls -l | awk '{print $8"\n"}'`
> echo $a
> -----
>
> shellcheck outputs:
>
> -----
> Line 1:
> a=`ls -l | awk '{print $8"\n"}'`
> ^-- SC2148: Tips depend on target shell and yours is unknown. Add a
> shebang or a 'shell' directive.
> ^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
> ^-- SC2012: Use find instead of ls to better handle non-alphanumeric
> filenames.

Both subjective preferences. In particular , "legacy" is a loaded term with
a negative connotation. If the code had $( ... ) one could equally well
say "Use backticks for wider portability" ! "Wider portability" is also
a loaded term but with a positive connotation.

> Did you mean: (apply this, apply all SC2006)
> a=$(ls -l | awk '{print $8"\n"}')
>
> Line 2:
> echo $a
> ^-- SC2086: Double quote to prevent globbing and word splitting.
>
> Did you mean: (apply this, apply all SC2086)
> echo "$a"
> -----
>
> When you add a shebang to fix the first message:
>
> -----
> #!/usr/bin/env bash
> a=`ls -l | awk '{print $8"\n"}'`
> echo $a
> -----
>
> shellcheck outputs:
>
> -----
> Line 2:
> a=`ls -l | awk '{print $8"\n"}'`
> ^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
> ^-- SC2012: Use find instead of ls to better handle non-alphanumeric
> filenames.
>
> Did you mean: (apply this, apply all SC2006)
> a=$(ls -l | awk '{print $8"\n"}')
>
> Line 3:
> echo $a
> ^-- SC2086: Double quote to prevent globbing and word splitting.
>
> Did you mean: (apply this, apply all SC2086)
> echo "$a"
> -----
>
> Note that at this point shellcheck is telling you of 3 issues in the
> script and of course that last one is the key to the problem the OP is
> specifically asking about.

By my count the site tells you about

1. A syntax error
2. Use find instead of ls
3. Use $( ... ) instead of ` ... `
4. Double quotes prevent globbing.
5. Double quotes prevent word splitting

It also wants to know what shell the user is using which is irrelevant. 2 and
3 are subjective (and irrelevant) , 1 and 4 are correct but irrelevant and
only 5 is key to the confusion of the opening poster. So I don't think that
shellcheck.net gave a good signal to noise ratio.

--
Any sufficiently advanced bug is indistinguishable from a feature.
Rich Kulawiec

Re: How do you insert a newline using AWK?

<xYZ0uJ1V4jl5DS97m@bongo-ra.co>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3813&group=comp.unix.shell#3813

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx45.ams4.POSTED!not-for-mail
From: spi...@gmail.com (Spiros Bousbouras)
Newsgroups: comp.unix.shell
Subject: Re: How do you insert a newline using AWK?
Message-ID: <xYZ0uJ1V4jl5DS97m@bongo-ra.co>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com> <s85u54$48l$1@dont-email.me> <s860p5$14s$1@dont-email.me>
<s863d3$e2u$1@dont-email.me>
In-Reply-To: <s863d3$e2u$1@dont-email.me>
X-Organisation: Weyland-Yutani
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Lines: 26
X-Complaints-To: http://netreport.virginmedia.com
NNTP-Posting-Date: Thu, 20 May 2021 20:59:38 UTC
Organization: virginmedia.com
Date: Thu, 20 May 2021 20:59:38 GMT
X-Received-Bytes: 2026
 by: Spiros Bousbouras - Thu, 20 May 2021 20:59 UTC

On Thu, 20 May 2021 11:40:03 -0500
Ed Morton <mortonspam@gmail.com> wrote:

> One of the nice things about running shellcheck is it gives you a link
> to click on where you can find out more about each issue so not only do
> we not have to identify the issues in the OPs code, we don't have to
> explain them either.

Noone has to identify or explain anything or indeed even read anything. Perhaps
people *enjoy* identifying the issues and explaining concepts.

> Just run the tool.... Not saying it'll
> uncover/explain everything but it goes a long way for most common issues
> and then we can help with any issues remaining after the code has been
> cleaned up to the point of making shellcheck happy.

If http://shellcheck.net provided a way to only flag objective issues (like
syntax errors) as opposed to subjective preferences of the author of the site
then it might have been useful on some occasions but , from the example you
posted in <s8633a$bqp$1@dont-email.me> , it seems to me just as likely to
send the user on a wild goose chase (or several).

--
Statistics are like a bikini. What they reveal is suggestive, but
what they conceal is vital.
Aaron Levenstein

Re: How do you insert a newline using AWK?

<s86p1p$14dff$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3815&group=comp.unix.shell#3815

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: How do you insert a newline using AWK?
Date: Thu, 20 May 2021 22:49:29 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <s86p1p$14dff$1@news.xmission.com>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com> <s8605c$c82$1@news-1.m-online.net> <s8633a$bqp$1@dont-email.me> <yTadvYnmFtQZvSJlY@bongo-ra.co>
Injection-Date: Thu, 20 May 2021 22:49:29 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1193455"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Thu, 20 May 2021 22:49 UTC

In article <yTadvYnmFtQZvSJlY@bongo-ra.co>,
Spiros Bousbouras <spibou@gmail.com> wrote:
....
>Pretty much anything can count as a potential issue. To some people using the
>shell at all as opposed to a "proper" language (like C or assembler) is a
>potential issue.

FTFY

--
The scent of awk programmers is a lot more attractive to women than
the scent of perl programmers.

(Mike Brennan, quoted in the "GAWK" manual)

Re: How do you insert a newline using AWK?

<s86png$7j0$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3816&group=comp.unix.shell#3816

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: mortons...@gmail.com (Ed Morton)
Newsgroups: comp.unix.shell
Subject: Re: How do you insert a newline using AWK?
Date: Thu, 20 May 2021 18:01:03 -0500
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <s86png$7j0$1@dont-email.me>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com>
<s85u54$48l$1@dont-email.me> <s8605c$c82$1@news-1.m-online.net>
<s8633a$bqp$1@dont-email.me> <yTadvYnmFtQZvSJlY@bongo-ra.co>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 20 May 2021 23:01:04 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="8366b2821f85bdb72c51465e5593864d";
logging-data="7776"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+WS7ad8wrxzCvwZyYKu12y"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.10.2
Cancel-Lock: sha1:eVFq1xx288QxBiPTGQ1emhStqjc=
In-Reply-To: <yTadvYnmFtQZvSJlY@bongo-ra.co>
X-Antivirus-Status: Clean
Content-Language: en-US
X-Antivirus: Avast (VPS 210520-4, 05/20/2021), Outbound message
 by: Ed Morton - Thu, 20 May 2021 23:01 UTC

On 5/20/2021 3:51 PM, Spiros Bousbouras wrote:
> On Thu, 20 May 2021 11:34:49 -0500
> Ed Morton <mortonspam@gmail.com> wrote:
>> On 5/20/2021 10:44 AM, Janis Papanagnou wrote:
>>> On 20.05.2021 17:10, Ed Morton wrote:
>
> [...]
>
>>>> Copy/paste your 2-line script into http://shellcheck.net and it'll tell
>>>> you what the problems are with it.
>
> [...]
>
>> The tool is just telling you about _potential_ issues, though, once you
>> understand the issue you can change the code as the tool suggests or add
>> a comment disabling the warning or just ignore it as you like.
>
> Pretty much anything can count as a potential issue.

shellcheck does a good job at identifying the issues you really should
think about. It's a great resource, especially for beginners.

<snip>

>
> By my count the site tells you about
>
> 1. A syntax error
> 2. Use find instead of ls
> 3. Use $( ... ) instead of ` ... `
> 4. Double quotes prevent globbing.
> 5. Double quotes prevent word splitting
>
> It also wants to know what shell the user is using which is irrelevant. 2 and
> 3 are subjective (and irrelevant) , 1 and 4 are correct but irrelevant and
> only 5 is key to the confusion of the opening poster. So I don't think that
> shellcheck.net gave a good signal to noise ratio.

I assume by "irrelevant" you mean "aren't causing this specific
problem". I strongly disagree that that categorization makes them
irrelevant - everything on that list regularly causes issues in scripts,
especially for beginners, and should be addressed in anyone's code
before they ask anyone else to help them debug it so we can rule out
those common issues as being the source of the current problem and not
waste time explaining them all for the OPs future, if not current,
benefit when the tool can do it.

Ed.

Re: How do you insert a newline using AWK?

<s87iv4$qpa$1@news-1.m-online.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3817&group=comp.unix.shell#3817

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: How do you insert a newline using AWK?
Date: Fri, 21 May 2021 08:11:48 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 55
Message-ID: <s87iv4$qpa$1@news-1.m-online.net>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com>
<s85u54$48l$1@dont-email.me> <s8605c$c82$1@news-1.m-online.net>
<s8633a$bqp$1@dont-email.me>
NNTP-Posting-Host: 2001:a61:252a:da01:54f3:ac33:b91d:8efb
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1621577508 27434 2001:a61:252a:da01:54f3:ac33:b91d:8efb (21 May 2021 06:11:48 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Fri, 21 May 2021 06:11:48 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
X-Enigmail-Draft-Status: N1110
In-Reply-To: <s8633a$bqp$1@dont-email.me>
 by: Janis Papanagnou - Fri, 21 May 2021 06:11 UTC

On 20.05.2021 18:34, Ed Morton wrote:
> On 5/20/2021 10:44 AM, Janis Papanagnou wrote:
>> On 20.05.2021 17:10, Ed Morton wrote:
>>> On 5/18/2021 2:33 PM, Chris Roberts wrote:
>>>> Using AWK, I am unable to insert a newline "\n"
>>>> Nothing I try seems to work here.
>>>> Not sure why it makes it all into a single line like this.
>>>> Does anyone know of a simple way to fix this?
>>>> And/Or an explanation?
>>>>
>>>> #ls -l
>>>> total 276
>>>> -rwxrwxrwx 1 crzzy1 crzzy1 211456 Sep 1 2020 NppToolBucket.dll
>>>> -rwxrwxrwx 1 crzzy1 crzzy1 212 Sep 3 2020 backup
>>>> -rwxrwxrwx 1 crzzy1 crzzy1 0 May 18 15:03 badip
>>>> -rwxrwxrwx 1 crzzy1 crzzy1 1399 May 11 11:53 ccc
>>>> -rwxrwxrwx 1 crzzy1 crzzy1 1622 Nov 2 2020 ccclab
>>>> -rwxrwxrwx 1 crzzy1 crzzy1 2217 May 7 13:09 cccp
>>>>
>>>> #a=`ls -l | awk '{print $8"\n"}'
>>>> #echo $a
>>>> 2020 2020 15:03 11:53 2020 13:09
>>>
>>> Copy/paste your 2-line script into http://shellcheck.net and it'll tell
>>> you what the problems are with it.
>>
>> Isn't the shell-checker's suggestion:
>> "Use find instead of ls to better handle non-alphanumeric filenames."
>> rather strange (to say the least)?
>>
>> (Shouldn't a shell-checker focus on the shell and not on used external
>> or compound commands? That it obviously cannot semantically grasp.)
>
> No, that's generally good advice, see
> https://mywiki.wooledge.org/ParsingLs.

I consider this spellcheck's message bad advice because it's extremely
misleading. It is speaking of "filenames" problems where here only the
date field is extracted. There's a lot better advice (IMO) to point out
that you might provide ls with options to show date in a standardized
(non-varying) format or to avoid ls and awk to use stat directly on the
files or whatever. What I mean is; a "shell" checker tool shall not make
(most likely wrong or misleading) suggestions about the whole semantical
context, but it shall rather focus on the _shell code_ issues. But don't
get me wrong; it's generally nice to have such a tool.

> The tool is just telling you about _potential_ issues, though, once you
> understand the issue you can change the code as the tool suggests or add
> a comment disabling the warning or just ignore it as you like.

The approach of potential issues, I think, is doomed to fail if I see
suggestions like the one I commented on.

Janis

Re: How do you insert a newline using AWK?

<s889iv$ca7$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3821&group=comp.unix.shell#3821

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: mortons...@gmail.com (Ed Morton)
Newsgroups: comp.unix.shell
Subject: Re: How do you insert a newline using AWK?
Date: Fri, 21 May 2021 07:37:50 -0500
Organization: A noiseless patient Spider
Lines: 67
Message-ID: <s889iv$ca7$1@dont-email.me>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com>
<s85u54$48l$1@dont-email.me> <s8605c$c82$1@news-1.m-online.net>
<s8633a$bqp$1@dont-email.me> <s87iv4$qpa$1@news-1.m-online.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 21 May 2021 12:37:51 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="302dcc8ce002ddc10e5bc7bf23620b5e";
logging-data="12615"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19LTrs11g9T1kwLZdbtFd6R"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.10.2
Cancel-Lock: sha1:DZSxrT8gcb6gtq6gEn+S/MWrVZg=
In-Reply-To: <s87iv4$qpa$1@news-1.m-online.net>
X-Antivirus-Status: Clean
Content-Language: en-US
X-Antivirus: Avast (VPS 210521-4, 05/21/2021), Outbound message
 by: Ed Morton - Fri, 21 May 2021 12:37 UTC

On 5/21/2021 1:11 AM, Janis Papanagnou wrote:
> On 20.05.2021 18:34, Ed Morton wrote:
>> On 5/20/2021 10:44 AM, Janis Papanagnou wrote:
>>> On 20.05.2021 17:10, Ed Morton wrote:
>>>> On 5/18/2021 2:33 PM, Chris Roberts wrote:
>>>>> Using AWK, I am unable to insert a newline "\n"
>>>>> Nothing I try seems to work here.
>>>>> Not sure why it makes it all into a single line like this.
>>>>> Does anyone know of a simple way to fix this?
>>>>> And/Or an explanation?
>>>>>
>>>>> #ls -l
>>>>> total 276
>>>>> -rwxrwxrwx 1 crzzy1 crzzy1 211456 Sep 1 2020 NppToolBucket.dll
>>>>> -rwxrwxrwx 1 crzzy1 crzzy1 212 Sep 3 2020 backup
>>>>> -rwxrwxrwx 1 crzzy1 crzzy1 0 May 18 15:03 badip
>>>>> -rwxrwxrwx 1 crzzy1 crzzy1 1399 May 11 11:53 ccc
>>>>> -rwxrwxrwx 1 crzzy1 crzzy1 1622 Nov 2 2020 ccclab
>>>>> -rwxrwxrwx 1 crzzy1 crzzy1 2217 May 7 13:09 cccp
>>>>>
>>>>> #a=`ls -l | awk '{print $8"\n"}'
>>>>> #echo $a
>>>>> 2020 2020 15:03 11:53 2020 13:09
>>>>
>>>> Copy/paste your 2-line script into http://shellcheck.net and it'll tell
>>>> you what the problems are with it.
>>>
>>> Isn't the shell-checker's suggestion:
>>> "Use find instead of ls to better handle non-alphanumeric filenames."
>>> rather strange (to say the least)?
>>>
>>> (Shouldn't a shell-checker focus on the shell and not on used external
>>> or compound commands? That it obviously cannot semantically grasp.)
>>
>> No, that's generally good advice, see
>> https://mywiki.wooledge.org/ParsingLs.
>
> I consider this spellcheck's message bad advice because it's extremely
> misleading. It is speaking of "filenames" problems where here only the
> date field is extracted. There's a lot better advice (IMO) to point out
> that you might provide ls with options to show date in a standardized
> (non-varying) format or to avoid ls and awk to use stat directly on the
> files or whatever. What I mean is; a "shell" checker tool shall not make
> (most likely wrong or misleading) suggestions about the whole semantical
> context, but it shall rather focus on the _shell code_ issues. But don't
> get me wrong; it's generally nice to have such a tool.
>
>> The tool is just telling you about _potential_ issues, though, once you
>> understand the issue you can change the code as the tool suggests or add
>> a comment disabling the warning or just ignore it as you like.
>
> The approach of potential issues, I think, is doomed to fail if I see
> suggestions like the one I commented on.

I'm struggling to accept that you seem to be arguing that "don't parse
the output of ls" is bad advice. It's one of the most common mistakes
that newcomers make. I'd be very disappointed in any kind of shell
script checking tool that DIDN'T produce a warning when it encounters
code that's doing it. I do think that a link to
https://mywiki.wooledge.org/ParsingLs or some other lengthier
description of all problems with parsing `ls` would be an improvement in
the full error description that shellcheck provides but I'm just happy
it provides something/anything to give the user a heads up that there's
an issue with that code.

Ed.

Re: How do you insert a newline using AWK?

<s89cc8$bmj$1@news-1.m-online.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3828&group=comp.unix.shell#3828

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!news.mixmin.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: How do you insert a newline using AWK?
Date: Sat, 22 May 2021 00:31:36 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 33
Message-ID: <s89cc8$bmj$1@news-1.m-online.net>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com>
<s85u54$48l$1@dont-email.me> <s8605c$c82$1@news-1.m-online.net>
<s8633a$bqp$1@dont-email.me> <s87iv4$qpa$1@news-1.m-online.net>
<s889iv$ca7$1@dont-email.me>
NNTP-Posting-Host: 2001:a61:252a:da01:54f3:ac33:b91d:8efb
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1621636296 11987 2001:a61:252a:da01:54f3:ac33:b91d:8efb (21 May 2021 22:31:36 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Fri, 21 May 2021 22:31:36 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
X-Enigmail-Draft-Status: N1110
In-Reply-To: <s889iv$ca7$1@dont-email.me>
 by: Janis Papanagnou - Fri, 21 May 2021 22:31 UTC

On 21.05.2021 14:37, Ed Morton wrote:
>
> I'm struggling to accept that you seem to be arguing that "don't parse
> the output of ls" is bad advice.

I think (and said) that this advice is misleading here, and that the
tool would serve better - specifically for "newcomers" as you write -
to abstain from giving something like "rule of thumbs for newbies" in
contexts where it doesn't apply, and that the tool should focus on
the primary domain it covers (the shell). I want to add that I might
come to another conclusion if the tool would be able to distinguish
unsafe from save usages; but the tool is (in this respect) obviously
far too primitive. It's just reacting (more or less) on keywords in
simple code pattern contexts (here a pipe). In other syntax contexts
the tool is much more sophisticated; e.g. it's *not* suggesting to
"quote every variable expansion" (as wiseacres often do) - the tool
knows where it's necessary and where not.

Janis

> It's one of the most common mistakes
> that newcomers make. I'd be very disappointed in any kind of shell
> script checking tool that DIDN'T produce a warning when it encounters
> code that's doing it. I do think that a link to
> https://mywiki.wooledge.org/ParsingLs or some other lengthier
> description of all problems with parsing `ls` would be an improvement in
> the full error description that shellcheck provides but I'm just happy
> it provides something/anything to give the user a heads up that there's
> an issue with that code.
>
> Ed.
>

shellcheck (Was: How do you insert a newline using AWK?)

<s89g5f$15qjq$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3829&group=comp.unix.shell#3829

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: shellcheck (Was: How do you insert a newline using AWK?)
Date: Fri, 21 May 2021 23:36:15 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <s89g5f$15qjq$1@news.xmission.com>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com> <s87iv4$qpa$1@news-1.m-online.net> <s889iv$ca7$1@dont-email.me> <s89cc8$bmj$1@news-1.m-online.net>
Injection-Date: Fri, 21 May 2021 23:36:15 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1239674"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Fri, 21 May 2021 23:36 UTC

In article <s89cc8$bmj$1@news-1.m-online.net>,
Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
....
>In other syntax contexts
>the tool is much more sophisticated; e.g. it's *not* suggesting to
>"quote every variable expansion" (as wiseacres often do) - the tool
>knows where it's necessary and where not.

Really? I thought it *did* complain about any unquoted variables
references.

It also complains about things like:

gawk '{ print $1 }'

because it thinks you need to use double quotes in order for variable
expansion to occur. I.e., it doesn't understand that $1 is an AWK
variable, not a shell variable.

It seems to me that it could be smarter about "command line programs" in
languages such as AWK.

--
It's possible that leasing office space to a Starbucks is a greater liability
in today's GOP than is hitting your mother on the head with a hammer.

Re: shellcheck (Was: How do you insert a newline using AWK?)

<s89iot$dg4$1@news-1.m-online.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3830&group=comp.unix.shell#3830

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: shellcheck (Was: How do you insert a newline using AWK?)
Date: Sat, 22 May 2021 02:20:45 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 56
Message-ID: <s89iot$dg4$1@news-1.m-online.net>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com>
<s87iv4$qpa$1@news-1.m-online.net> <s889iv$ca7$1@dont-email.me>
<s89cc8$bmj$1@news-1.m-online.net> <s89g5f$15qjq$1@news.xmission.com>
NNTP-Posting-Host: 2001:a61:252a:da01:3189:2fa9:b207:c07a
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1621642845 13828 2001:a61:252a:da01:3189:2fa9:b207:c07a (22 May 2021 00:20:45 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Sat, 22 May 2021 00:20:45 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
X-Enigmail-Draft-Status: N1110
In-Reply-To: <s89g5f$15qjq$1@news.xmission.com>
 by: Janis Papanagnou - Sat, 22 May 2021 00:20 UTC

On 22.05.2021 01:36, Kenny McCormack wrote:
> In article <s89cc8$bmj$1@news-1.m-online.net>,
> Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
> ...
>> In other syntax contexts
>> the tool is much more sophisticated; e.g. it's *not* suggesting to
>> "quote every variable expansion" (as wiseacres often do) - the tool
>> knows where it's necessary and where not.
>
> Really? I thought it *did* complain about any unquoted variables
> references.

It recognizes that

b="1 2" ; case $b in ... esac

and

b=1 ; echo $b

are both okay, but that

b="1 2" ; echo $b

isn't. - Quite sophisticated, I'd say.

OTOH, it doesn't detect that this works correctly

b="1 2" ; IFS= ; echo $b

> It also complains about things like:
>
> gawk '{ print $1 }'
>
> because it thinks you need to use double quotes in order for variable
> expansion to occur. I.e., it doesn't understand that $1 is an AWK
> variable, not a shell variable.

Hmm, okay. - I'd have expected that such embedded scripts would be
properly analyzed (especially if the given single-quoting prevents
any variable expansion inside; it could be considered a black-box).

But to be honest, I have just tried a hand full of code patterns to
see how clever or stupid it is. I suppose there are a couple things
where we'd be surprised (false positives and false negatives, so to
say).

>
> It seems to me that it could be smarter about "command line programs" in
> languages such as AWK.

Indeed.

Janis

Re: shellcheck (Was: How do you insert a newline using AWK?)

<s8a6k8$57c$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3831&group=comp.unix.shell#3831

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: mortons...@gmail.com (Ed Morton)
Newsgroups: comp.unix.shell
Subject: Re: shellcheck (Was: How do you insert a newline using AWK?)
Date: Sat, 22 May 2021 00:59:35 -0500
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <s8a6k8$57c$1@dont-email.me>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com>
<s87iv4$qpa$1@news-1.m-online.net> <s889iv$ca7$1@dont-email.me>
<s89cc8$bmj$1@news-1.m-online.net> <s89g5f$15qjq$1@news.xmission.com>
<s89iot$dg4$1@news-1.m-online.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 22 May 2021 05:59:36 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="1e9dccfeca0af63b5760f8c86b924f03";
logging-data="5356"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/nhS2GO7WzpzQB883XdX0K"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.10.2
Cancel-Lock: sha1:UeAgeSG3O6ftQKybpQvqjbHXdxc=
In-Reply-To: <s89iot$dg4$1@news-1.m-online.net>
X-Antivirus-Status: Clean
Content-Language: en-US
X-Antivirus: Avast (VPS 210521-12, 05/21/2021), Outbound message
 by: Ed Morton - Sat, 22 May 2021 05:59 UTC

On 5/21/2021 7:20 PM, Janis Papanagnou wrote:
> On 22.05.2021 01:36, Kenny McCormack wrote:
<snip>
>> It also complains about things like:
>>
>> gawk '{ print $1 }'

Not it doesn't.

#!/usr/bin/env bash
gawk '{ print $1 }'

$ shellcheck myscript
No issues detected!

Ed.

Re: shellcheck (Was: How do you insert a newline using AWK?)

<s8abqh$kf2$1@news-1.m-online.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3832&group=comp.unix.shell#3832

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: shellcheck (Was: How do you insert a newline using AWK?)
Date: Sat, 22 May 2021 09:28:17 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 52
Message-ID: <s8abqh$kf2$1@news-1.m-online.net>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com>
<s87iv4$qpa$1@news-1.m-online.net> <s889iv$ca7$1@dont-email.me>
<s89cc8$bmj$1@news-1.m-online.net> <s89g5f$15qjq$1@news.xmission.com>
<s89iot$dg4$1@news-1.m-online.net>
NNTP-Posting-Host: 2001:a61:252a:da01:3189:2fa9:b207:c07a
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1621668497 20962 2001:a61:252a:da01:3189:2fa9:b207:c07a (22 May 2021 07:28:17 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Sat, 22 May 2021 07:28:17 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
In-Reply-To: <s89iot$dg4$1@news-1.m-online.net>
 by: Janis Papanagnou - Sat, 22 May 2021 07:28 UTC

On 22.05.2021 02:20, Janis Papanagnou wrote:
> On 22.05.2021 01:36, Kenny McCormack wrote:
>> In article <s89cc8$bmj$1@news-1.m-online.net>,
>> Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
>> ...
>>> In other syntax contexts
>>> the tool is much more sophisticated; e.g. it's *not* suggesting to
>>> "quote every variable expansion" (as wiseacres often do) - the tool
>>> knows where it's necessary and where not.
>>
>> Really? I thought it *did* complain about any unquoted variables
>> references.
>
> It recognizes that
>
> b="1 2" ; case $b in ... esac
>
> and
>
> b=1 ; echo $b
>
> are both okay, but that
>
> b="1 2" ; echo $b
>
> isn't. - Quite sophisticated, I'd say.
>
> OTOH, it doesn't detect that this works correctly
>
> b="1 2" ; IFS= ; echo $b
>

The first impression often has to be corrected after having a closer
look into the issue. From the next two sample codes the first one is
considered okay, but not the second one.

if [ "$1" -eq 0 ]
then b="1 2"
else b=1
fi
echo $b

if [ "$1" -ne 0 ]
then b=1
else b="1 2"
fi
echo $b

We can see that the tool uses only a primitive heuristic analysis.

Janis

Re: shellcheck (Was: How do you insert a newline using AWK?)

<s8ac15$kfg$1@news-1.m-online.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3833&group=comp.unix.shell#3833

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: shellcheck (Was: How do you insert a newline using AWK?)
Date: Sat, 22 May 2021 09:31:49 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 26
Message-ID: <s8ac15$kfg$1@news-1.m-online.net>
References: <fcb43d64-bbcd-48cd-bbd8-7fb7590e181cn@googlegroups.com>
<s87iv4$qpa$1@news-1.m-online.net> <s889iv$ca7$1@dont-email.me>
<s89cc8$bmj$1@news-1.m-online.net> <s89g5f$15qjq$1@news.xmission.com>
<s89iot$dg4$1@news-1.m-online.net> <s8a6k8$57c$1@dont-email.me>
NNTP-Posting-Host: 2001:a61:252a:da01:3189:2fa9:b207:c07a
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1621668709 20976 2001:a61:252a:da01:3189:2fa9:b207:c07a (22 May 2021 07:31:49 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Sat, 22 May 2021 07:31:49 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
In-Reply-To: <s8a6k8$57c$1@dont-email.me>
 by: Janis Papanagnou - Sat, 22 May 2021 07:31 UTC

On 22.05.2021 07:59, Ed Morton wrote:
> On 5/21/2021 7:20 PM, Janis Papanagnou wrote:
>> On 22.05.2021 01:36, Kenny McCormack wrote:
> <snip>
>>> It also complains about things like:
>>>
>>> gawk '{ print $1 }'
>
> Not it doesn't.

I haven't verified Kenny's example, but I've just tried the statement

gawk "{ print $1 }"

which also gives no warning.

Janis

> #!/usr/bin/env bash
> gawk '{ print $1 }'
>
> $ shellcheck myscript
> No issues detected!
>
> Ed.

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor