Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

13. ... r-q1


devel / comp.unix.shell / Re: Gracefully quoting with `bash -c`.

SubjectAuthor
* Re: Gracefully quoting with `bash -c`.Janis Papanagnou
+- Re: Gracefully quoting with `bash -c`.hongy...@gmail.com
`* Re: Gracefully quoting with `bash -c`.hongy...@gmail.com
 `- Re: Gracefully quoting with `bash -c`.Janis Papanagnou

1
Re: Gracefully quoting with `bash -c`.

<s4ttd3$bki$1@news-1.m-online.net>

 copy mid

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

 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: Gracefully quoting with `bash -c`.
Date: Sun, 11 Apr 2021 06:19:47 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 27
Message-ID: <s4ttd3$bki$1@news-1.m-online.net>
References: <807d70f6-913e-4da1-a90e-574749ec4695n@googlegroups.com>
NNTP-Posting-Host: 2001:a61:252a:da01:887a:3a99:3d5d:63c8
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1618114787 11922 2001:a61:252a:da01:887a:3a99:3d5d:63c8 (11 Apr 2021 04:19:47 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Sun, 11 Apr 2021 04:19:47 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
In-Reply-To: <807d70f6-913e-4da1-a90e-574749ec4695n@googlegroups.com>
 by: Janis Papanagnou - Sun, 11 Apr 2021 04:19 UTC

On 11.04.2021 03:32, hongy...@gmail.com wrote:
> See the following two usages:
>
> werner@X10DAi:~$ bash -c "ip -4 route |egrep ^default | awk '{print \$5}'"
> enp4s0
> werner@X10DAi:~$ bash -c 'ip -4 route |egrep ^default | awk "{print \$5}"'
> enp4s0
>
> Which one is preferable? Or, is there any other better usage for this situation?

I'd probably prefer the _outer_ context uninterpreted with single quotes

sh -c 'ip -4 route | awk "/^default/{print \$5}"'

or probably just rely on any POSIX shell being used as interactive shell
and do just

ip -4 route | awk '/^default/{print $5}'

Janis

>
> Regards,
> HY
>

Re: Gracefully quoting with `bash -c`.

<6051ce0c-c943-4b79-9ff2-cb1a6ee0f47fn@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a37:a54f:: with SMTP id o76mr21709895qke.95.1618124553473;
Sun, 11 Apr 2021 00:02:33 -0700 (PDT)
X-Received: by 2002:a0c:db0e:: with SMTP id d14mr22639761qvk.0.1618124553272;
Sun, 11 Apr 2021 00:02:33 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.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: Sun, 11 Apr 2021 00:02:32 -0700 (PDT)
In-Reply-To: <s4ttd3$bki$1@news-1.m-online.net>
Injection-Info: google-groups.googlegroups.com; posting-host=103.138.53.55; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 103.138.53.55
References: <807d70f6-913e-4da1-a90e-574749ec4695n@googlegroups.com> <s4ttd3$bki$1@news-1.m-online.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6051ce0c-c943-4b79-9ff2-cb1a6ee0f47fn@googlegroups.com>
Subject: Re: Gracefully quoting with `bash -c`.
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Sun, 11 Apr 2021 07:02:33 +0000
Content-Type: text/plain; charset="UTF-8"
 by: hongy...@gmail.com - Sun, 11 Apr 2021 07:02 UTC

On Sunday, April 11, 2021 at 12:19:51 PM UTC+8, Janis Papanagnou wrote:
> On 11.04.2021 03:32, hongy...@gmail.com wrote:
> > See the following two usages:
> >
> > werner@X10DAi:~$ bash -c "ip -4 route |egrep ^default | awk '{print \$5}'"
> > enp4s0
> > werner@X10DAi:~$ bash -c 'ip -4 route |egrep ^default | awk "{print \$5}"'
> > enp4s0
> >
> > Which one is preferable? Or, is there any other better usage for this situation?
> I'd probably prefer the _outer_ context uninterpreted with single quotes
>
> sh -c 'ip -4 route | awk "/^default/{print \$5}"'

Thank you for sharing your opinion.

> or probably just rely on any POSIX shell being used as interactive shell
> and do just
>
> ip -4 route | awk '/^default/{print $5}'

I want to invoke it from within systemd unit file, so the shell interpreter must be given with absolute path.
HY

Re: Gracefully quoting with `bash -c`.

<dcfd1a10-39b5-44a1-99e5-8e3179ad014en@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:620a:a83:: with SMTP id v3mr14310771qkg.6.1618124805870;
Sun, 11 Apr 2021 00:06:45 -0700 (PDT)
X-Received: by 2002:ac8:7a78:: with SMTP id w24mr1270733qtt.79.1618124805707;
Sun, 11 Apr 2021 00:06:45 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.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: Sun, 11 Apr 2021 00:06:45 -0700 (PDT)
In-Reply-To: <s4ttd3$bki$1@news-1.m-online.net>
Injection-Info: google-groups.googlegroups.com; posting-host=211.23.211.40; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 211.23.211.40
References: <807d70f6-913e-4da1-a90e-574749ec4695n@googlegroups.com> <s4ttd3$bki$1@news-1.m-online.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <dcfd1a10-39b5-44a1-99e5-8e3179ad014en@googlegroups.com>
Subject: Re: Gracefully quoting with `bash -c`.
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Sun, 11 Apr 2021 07:06:45 +0000
Content-Type: text/plain; charset="UTF-8"
 by: hongy...@gmail.com - Sun, 11 Apr 2021 07:06 UTC

On Sunday, April 11, 2021 at 12:19:51 PM UTC+8, Janis Papanagnou wrote:
> On 11.04.2021 03:32, hongy...@gmail.com wrote:
> > See the following two usages:
> >
> > werner@X10DAi:~$ bash -c "ip -4 route |egrep ^default | awk '{print \$5}'"
> > enp4s0
> > werner@X10DAi:~$ bash -c 'ip -4 route |egrep ^default | awk "{print \$5}"'
> > enp4s0
> >
> > Which one is preferable? Or, is there any other better usage for this situation?
> I'd probably prefer the _outer_ context uninterpreted with single quotes
>
> sh -c 'ip -4 route | awk "/^default/{print \$5}"'

What do you think of the following form?

$ sh -c 'ip -4 route | awk '\''/^default/{print $5}'\'''
enp4s0

HY

>
> or probably just rely on any POSIX shell being used as interactive shell
> and do just
>
> ip -4 route | awk '/^default/{print $5}'
>
>
> Janis
>
> >
> > Regards,
> > HY
> >

Re: Gracefully quoting with `bash -c`.

<s4u7t1$eib$1@news-1.m-online.net>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.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: Gracefully quoting with `bash -c`.
Date: Sun, 11 Apr 2021 09:18:57 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 27
Message-ID: <s4u7t1$eib$1@news-1.m-online.net>
References: <807d70f6-913e-4da1-a90e-574749ec4695n@googlegroups.com>
<s4ttd3$bki$1@news-1.m-online.net>
<dcfd1a10-39b5-44a1-99e5-8e3179ad014en@googlegroups.com>
NNTP-Posting-Host: 2001:a61:252a:da01:4de4:e129:1e02:65bc
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1618125537 14923 2001:a61:252a:da01:4de4:e129:1e02:65bc (11 Apr 2021 07:18:57 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Sun, 11 Apr 2021 07:18:57 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
In-Reply-To: <dcfd1a10-39b5-44a1-99e5-8e3179ad014en@googlegroups.com>
 by: Janis Papanagnou - Sun, 11 Apr 2021 07:18 UTC

On 11.04.2021 09:06, hongy...@gmail.com wrote:
> On Sunday, April 11, 2021 at 12:19:51 PM UTC+8, Janis Papanagnou wrote:
>> On 11.04.2021 03:32, hongy...@gmail.com wrote:
>>>
>>> Which one is preferable? Or, is there any other better usage for this situation?
>> I'd probably prefer the _outer_ context uninterpreted with single quotes
>>
>> sh -c 'ip -4 route | awk "/^default/{print \$5}"'
>
> What do you think of the following form?
>
> $ sh -c 'ip -4 route | awk '\''/^default/{print $5}'\'''
> enp4s0

Too much of a quote/escape mess in my opinion.

If you need the sh -c then I'd stay with the one quoted above

sh -c 'ip -4 route | awk "/^default/{print \$5}"'

Janis

> HY
>

1
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor