Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Open Channel D..." -- Napoleon Solo, The Man From U.N.C.L.E.


devel / comp.unix.shell / Re: Bash: How to "sanitise" a string before it is echoed?

SubjectAuthor
* How to "sanitise" a string before it is echoed?Ottavio Caruso
+* Bash: How to "sanitise" a string before it is echoed?Ottavio Caruso
|`* Re: Bash: How to "sanitise" a string before it is echoed?Tavis Ormandy
| `* Re: Bash: How to "sanitise" a string before it is echoed?Ottavio Caruso
|  `* Re: Bash: How to "sanitise" a string before it is echoed?Tavis Ormandy
|   `* Re: Bash: How to "sanitise" a string before it is echoed?Tavis Ormandy
|    `- Re: Bash: How to "sanitise" a string before it is echoed?Tavis Ormandy
+* Re: How to "sanitise" a string before it is echoed?Janis Papanagnou
|`* Re: How to "sanitise" a string before it is echoed?Ottavio Caruso
| +- Re: How to "sanitise" a string before it is echoed?Kaz Kylheku
| `- Re: How to "sanitise" a string before it is echoed?Janis Papanagnou
`* Re: How to "sanitise" a string before it is echoed?Keith Thompson
 `- Re: How to "sanitise" a string before it is echoed?Ottavio Caruso

1
How to "sanitise" a string before it is echoed?

<sc48on$605$1@dont-email.me>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ottavio2...@yahoo.com (Ottavio Caruso)
Newsgroups: comp.unix.shell
Subject: How to "sanitise" a string before it is echoed?
Date: Wed, 7 Jul 2021 14:04:22 +0100
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <sc48on$605$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 7 Jul 2021 13:04:23 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d19eeb56537ba8694242a84f4b349dfa";
logging-data="6149"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+tb6GloiHoCERH5p+z8bIeME+I9SsMfD0="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:igsEK3OH+qjSW5/WSFAZoW/I654=
X-No-Archive: yes
Content-Language: en-GB
X-Mozilla-News-Host: snews://news.eternal-september.org:563
 by: Ottavio Caruso - Wed, 7 Jul 2021 13:04 UTC

Hi,

I've written this one liner function to remove diacritics from a string
and convert everything to lowercase:

rd ()
{ echo $* | iconv -c -t ascii//TRANSLIT | tr '[:upper:]' '[:lower:]'
}

This works:

$ rd Est-ce que ces logiciels appartiennent à Nicolas?
est-ce que ces logiciels appartiennent a nicolas?

This also works:

$ rd "Nicolas, est-ce que c'est tachambre ou celle de ta sœur?"
nicolas, est-ce que c'est tachambre ou celle de ta soeur?

But this doesn't:
$ rd Nicolas, est-ce que c'est ta chambre ou celle de ta sœur?
>

Note the culprit is the single quote in "c'est".

I am too lazy to wrap my sentences within quotes. How can I modify that
function to do that for me?

Thanks.

--
Ottavio Caruso

Bash: How to "sanitise" a string before it is echoed?

<sc49gn$b84$1@dont-email.me>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ottavio2...@yahoo.com (Ottavio Caruso)
Newsgroups: comp.unix.shell
Subject: Bash: How to "sanitise" a string before it is echoed?
Date: Wed, 7 Jul 2021 14:17:11 +0100
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <sc49gn$b84$1@dont-email.me>
References: <sc48on$605$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 7 Jul 2021 13:17:12 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d19eeb56537ba8694242a84f4b349dfa";
logging-data="11524"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/wFkfcBoua6CklgVML6mROobMucXCZAhA="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:+jbYeNPX0rExMPDfEvDs88Qr8Ds=
X-No-Archive: yes
In-Reply-To: <sc48on$605$1@dont-email.me>
Content-Language: en-GB
 by: Ottavio Caruso - Wed, 7 Jul 2021 13:17 UTC

On 07/07/2021 14:04, Ottavio Caruso wrote:
> Hi,
>
> I've written this one liner function to remove diacritics from a string
> and convert everything to lowercase:
>
>
> rd ()
> {
>     echo $* | iconv -c -t ascii//TRANSLIT | tr '[:upper:]' '[:lower:]'
> }
>
>
> This works:
>
> $ rd Est-ce que ces logiciels  appartiennent à Nicolas?
> est-ce que ces logiciels appartiennent a nicolas?
>
> This also works:
>
> $ rd "Nicolas, est-ce que c'est tachambre ou celle de ta sœur?"
> nicolas, est-ce que c'est tachambre ou celle de ta soeur?
>
> But this doesn't:
> $ rd Nicolas, est-ce que c'est ta chambre ou celle de ta sœur?
> >
>
> Note the culprit is the single quote in "c'est".
>
> I am too lazy to wrap my sentences within quotes. How can I modify that
> function to do that for me?

Sorry, I forgot to say it's bash.

--
Ottavio Caruso

Re: Bash: How to "sanitise" a string before it is echoed?

<iklqr2FfqhnU1@mid.individual.net>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: tav...@gmail.com (Tavis Ormandy)
Newsgroups: comp.unix.shell
Subject: Re: Bash: How to "sanitise" a string before it is echoed?
Date: 7 Jul 2021 14:08:34 GMT
Lines: 19
Message-ID: <iklqr2FfqhnU1@mid.individual.net>
References: <sc48on$605$1@dont-email.me> <sc49gn$b84$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net +93rvUIu9uPNYDZ2O/ErbQsqdk9WWt9Akh+QYM8bUmTKN+/XbX
Cancel-Lock: sha1:AP86Rv6eFVQVYT4ZqwtiLyUYqFE=
User-Agent: slrn/1.0.3 (Linux)
 by: Tavis Ormandy - Wed, 7 Jul 2021 14:08 UTC

On 2021-07-07, Ottavio Caruso wrote:
>> I am too lazy to wrap my sentences within quotes. How can I modify that
>> function to do that for me?
>
> Sorry, I forgot to say it's bash

Why not prompt for the input instead? e.g.

rd ()
{     read -ep 'rd> ' l && iconv -c -t ascii//TRANSLIT <<< "$l" | ...
}

Tavis.

--
_o) $ lynx lock.cmpxchg8b.com
/\\ _o) _o) $ finger taviso@sdf.org
_\_V _( ) _( ) @taviso

Re: How to "sanitise" a string before it is echoed?

<sc4hbu$brd$1@news-1.m-online.net>

 copy mid

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

 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 to "sanitise" a string before it is echoed?
Date: Wed, 7 Jul 2021 17:31:09 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 60
Message-ID: <sc4hbu$brd$1@news-1.m-online.net>
References: <sc48on$605$1@dont-email.me>
NNTP-Posting-Host: 2001:a61:241e:cc01:f959:8494:6a2:cb16
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: news-1.m-online.net 1625671870 12141 2001:a61:241e:cc01:f959:8494:6a2:cb16 (7 Jul 2021 15:31:10 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Wed, 7 Jul 2021 15:31:10 +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: <sc48on$605$1@dont-email.me>
 by: Janis Papanagnou - Wed, 7 Jul 2021 15:31 UTC

On 07.07.2021 15:04, Ottavio Caruso wrote:
> Hi,
>
> I've written this one liner function to remove diacritics from a string
> and convert everything to lowercase:
>
>
> rd ()
> {
> echo $* | iconv -c -t ascii//TRANSLIT | tr '[:upper:]' '[:lower:]'
> }
>
>
> This works:
>
> $ rd Est-ce que ces logiciels appartiennent à Nicolas?
> est-ce que ces logiciels appartiennent a nicolas?
>
> This also works:
>
> $ rd "Nicolas, est-ce que c'est tachambre ou celle de ta sœur?"
> nicolas, est-ce que c'est tachambre ou celle de ta soeur?
>
> But this doesn't:
> $ rd Nicolas, est-ce que c'est ta chambre ou celle de ta sœur?
>>
>
> Note the culprit is the single quote in "c'est".
>
> I am too lazy to wrap my sentences within quotes. How can I modify that
> function to do that for me?

While the function should probably be changed to use "$@" instead of $*
it is *not* the function that throws the error, it is the function call.
Every character that is shell syntax relevant will spoil interpretation.
Try a parenthesis, try what happens if you have files named sœurA, sœurB
in your working directory, try strings that are preceded by $ symbols.
All will break the interpretation of your code.

You may escape all critical characters, like

rd Nicolas, est-ce que c\'est ta chambre ou celle de ta sœur?

but the cleanest form is to quote the function argument.

And change your function to

echo "$@" | ...

to not get other side effects that you not yet notice; try

touch sœurA sœurB

and call your function to see the undesired effect.

Janis

> Thanks.
>

Re: How to "sanitise" a string before it is echoed?

<87fswq83r4.fsf@nosuchdomain.example.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.unix.shell
Subject: Re: How to "sanitise" a string before it is echoed?
Date: Wed, 07 Jul 2021 09:53:19 -0700
Organization: None to speak of
Lines: 44
Message-ID: <87fswq83r4.fsf@nosuchdomain.example.com>
References: <sc48on$605$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="3dc7a7dd1222d96e79a8876407c639ec";
logging-data="3913"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+GxaX4vAydwdUVzbR7oUTU"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:d3a9ecQUbTPn7YikTQd8HM66NSU=
sha1:aLCmbqwPgbs/DYW+hfQKMcdaAE8=
 by: Keith Thompson - Wed, 7 Jul 2021 16:53 UTC

Ottavio Caruso <ottavio2006-usenet2012@yahoo.com> writes:
> I've written this one liner function to remove diacritics from a
> string and convert everything to lowercase:
>
>
> rd ()
> {
> echo $* | iconv -c -t ascii//TRANSLIT | tr '[:upper:]' '[:lower:]'
> }
>
>
> This works:
>
> $ rd Est-ce que ces logiciels appartiennent à Nicolas?
> est-ce que ces logiciels appartiennent a nicolas?
>
> This also works:
>
> $ rd "Nicolas, est-ce que c'est tachambre ou celle de ta sœur?"
> nicolas, est-ce que c'est tachambre ou celle de ta soeur?
>
> But this doesn't:
> $ rd Nicolas, est-ce que c'est ta chambre ou celle de ta sœur?
>>
>
> Note the culprit is the single quote in "c'est".
>
> I am too lazy to wrap my sentences within quotes. How can I modify
> that function to do that for me?

You can't.

If you don't quote your arguments, then you can't have arguments with
quotation marks in them. This command:

$ rd foo'bar

is invalid (or rather incomplete), and rd is never invoked. There's
nothing you can change in rd to fix that.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: How to "sanitise" a string before it is echoed?

<sc4ub9$70i$1@dont-email.me>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ottavio2...@yahoo.com (Ottavio Caruso)
Newsgroups: comp.unix.shell
Subject: Re: How to "sanitise" a string before it is echoed?
Date: Wed, 7 Jul 2021 20:12:41 +0100
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <sc4ub9$70i$1@dont-email.me>
References: <sc48on$605$1@dont-email.me> <sc4hbu$brd$1@news-1.m-online.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 7 Jul 2021 19:12:41 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4b05ee0d94de929ef0a572e1bba1b35f";
logging-data="7186"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19fx1vyiBQVQl0rZGerRSbyDGwEmrTG/Ig="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:sZE393AEduCTLEosVQ6CYItD/6o=
X-No-Archive: yes
In-Reply-To: <sc4hbu$brd$1@news-1.m-online.net>
Content-Language: en-GB
 by: Ottavio Caruso - Wed, 7 Jul 2021 19:12 UTC

On 07/07/2021 16:31, Janis Papanagnou wrote:

>
> And change your function to
>
> echo "$@" | ...
>
> to not get other side effects that you not yet notice; try
>
> touch sœurA sœurB
>
> and call your function to see the undesired effect.
>

That doesn't seem to work:

$ rd () { echo "$@" | iconv -c -t ascii//TRANSLIT | tr '[:upper:]'
'[:lower:]'; }
$ rd Ce CD n'est pas le tien
>

--
Ottavio Caruso

Re: Bash: How to "sanitise" a string before it is echoed?

<sc4ugi$70i$2@dont-email.me>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ottavio2...@yahoo.com (Ottavio Caruso)
Newsgroups: comp.unix.shell
Subject: Re: Bash: How to "sanitise" a string before it is echoed?
Date: Wed, 7 Jul 2021 20:15:30 +0100
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <sc4ugi$70i$2@dont-email.me>
References: <sc48on$605$1@dont-email.me> <sc49gn$b84$1@dont-email.me>
<iklqr2FfqhnU1@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 7 Jul 2021 19:15:31 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4b05ee0d94de929ef0a572e1bba1b35f";
logging-data="7186"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19LxRZM0ATeh06euplgnQ5D9+j++IeqcZg="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:Uki9qpGCy4P2rL0SYWPbPuYtFWU=
X-No-Archive: yes
In-Reply-To: <iklqr2FfqhnU1@mid.individual.net>
Content-Language: en-GB
 by: Ottavio Caruso - Wed, 7 Jul 2021 19:15 UTC

On 07/07/2021 15:08, Tavis Ormandy wrote:
> On 2021-07-07, Ottavio Caruso wrote:
>>> I am too lazy to wrap my sentences within quotes. How can I modify that
>>> function to do that for me?
>>
>> Sorry, I forgot to say it's bash
>
> Why not prompt for the input instead? e.g.
>
> rd ()
> {
>     read -ep 'rd> ' l && iconv -c -t ascii//TRANSLIT <<< "$l" | ...
> }
>
> Tavis.
>

That doesn't work either:

$ rd () {
read -ep 'rd> ' l && iconv -c -t ascii//TRANSLIT <<< "$l" | tr
'[:upper:]' '[:lower:]'; }
$ rd Ce CD n'est pas le tien
>

--
Ottavio Caruso

Re: How to "sanitise" a string before it is echoed?

<sc4uj8$70i$3@dont-email.me>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.niel.me!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ottavio2...@yahoo.com (Ottavio Caruso)
Newsgroups: comp.unix.shell
Subject: Re: How to "sanitise" a string before it is echoed?
Date: Wed, 7 Jul 2021 20:16:56 +0100
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <sc4uj8$70i$3@dont-email.me>
References: <sc48on$605$1@dont-email.me>
<87fswq83r4.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 7 Jul 2021 19:16:56 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4b05ee0d94de929ef0a572e1bba1b35f";
logging-data="7186"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19dGtB2QkUsFHfLSp4VomRw+/YEH0KDVGw="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:5z4MwYrbSBU/quyXxHH1sZ+Kieg=
X-No-Archive: yes
In-Reply-To: <87fswq83r4.fsf@nosuchdomain.example.com>
Content-Language: en-GB
 by: Ottavio Caruso - Wed, 7 Jul 2021 19:16 UTC

On 07/07/2021 17:53, Keith Thompson wrote:
> Ottavio Caruso <ottavio2006-usenet2012@yahoo.com> writes:
>> I've written this one liner function to remove diacritics from a
>> string and convert everything to lowercase:
>>
>>
>> rd ()
>> {
>> echo $* | iconv -c -t ascii//TRANSLIT | tr '[:upper:]' '[:lower:]'
>> }
>>
>>
>> This works:
>>
>> $ rd Est-ce que ces logiciels appartiennent à Nicolas?
>> est-ce que ces logiciels appartiennent a nicolas?
>>
>> This also works:
>>
>> $ rd "Nicolas, est-ce que c'est tachambre ou celle de ta sœur?"
>> nicolas, est-ce que c'est tachambre ou celle de ta soeur?
>>
>> But this doesn't:
>> $ rd Nicolas, est-ce que c'est ta chambre ou celle de ta sœur?
>>>
>>
>> Note the culprit is the single quote in "c'est".
>>
>> I am too lazy to wrap my sentences within quotes. How can I modify
>> that function to do that for me?
>
> You can't.
>
> If you don't quote your arguments, then you can't have arguments with
> quotation marks in them. This command:
>
> $ rd foo'bar
>
> is invalid (or rather incomplete), and rd is never invoked. There's
> nothing you can change in rd to fix that.
>

Amen to that, then.

--
Ottavio Caruso

Re: Bash: How to "sanitise" a string before it is echoed?

<ikmd1fFjc9mU1@mid.individual.net>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: tav...@gmail.com (Tavis Ormandy)
Newsgroups: comp.unix.shell
Subject: Re: Bash: How to "sanitise" a string before it is echoed?
Date: 7 Jul 2021 19:19:11 GMT
Lines: 32
Message-ID: <ikmd1fFjc9mU1@mid.individual.net>
References: <sc48on$605$1@dont-email.me> <sc49gn$b84$1@dont-email.me>
<iklqr2FfqhnU1@mid.individual.net> <sc4ugi$70i$2@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net GB4aKGLG+SZPtkXAWJNgtQEttzooZ4Pc5IovIoRqiWGlwzTzEF
Cancel-Lock: sha1:cMr90LmHlBdyhlslvubaMiydS24=
User-Agent: slrn/1.0.3 (Linux)
 by: Tavis Ormandy - Wed, 7 Jul 2021 19:19 UTC

On 2021-07-07, Ottavio Caruso wrote:
> On 07/07/2021 15:08, Tavis Ormandy wrote:
>> On 2021-07-07, Ottavio Caruso wrote:
>>>> I am too lazy to wrap my sentences within quotes. How can I modify that
>>>> function to do that for me?
>>>
>>> Sorry, I forgot to say it's bash
>>
>> Why not prompt for the input instead? e.g.
>>
>> rd ()
>> {
>>     read -ep 'rd> ' l && iconv -c -t ascii//TRANSLIT <<< "$l" | ...
>> }
>>
>> Tavis.
>>
>
> That doesn't work either:
>

It prompts instead. You type 'rd' then press enter, then enter your
string, then press enter again. It is one additional keypress.

Every other alternative will require quoting or escaping.

Tavis.

--
_o) $ lynx lock.cmpxchg8b.com
/\\ _o) _o) $ finger taviso@sdf.org
_\_V _( ) _( ) @taviso

Re: Bash: How to "sanitise" a string before it is echoed?

<ikmdcfFjc9mU2@mid.individual.net>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: tav...@gmail.com (Tavis Ormandy)
Newsgroups: comp.unix.shell
Subject: Re: Bash: How to "sanitise" a string before it is echoed?
Date: 7 Jul 2021 19:25:03 GMT
Lines: 15
Message-ID: <ikmdcfFjc9mU2@mid.individual.net>
References: <sc48on$605$1@dont-email.me> <sc49gn$b84$1@dont-email.me>
<iklqr2FfqhnU1@mid.individual.net> <sc4ugi$70i$2@dont-email.me>
<ikmd1fFjc9mU1@mid.individual.net>
X-Trace: individual.net zJb/y5k9Ys/gijYePFq5bwQnMt9tUKyMtr24iZGtpeZJiE+7zy
Cancel-Lock: sha1:Wiiv2tOw1TfxJLay4LBBJfO0sx8=
User-Agent: slrn/1.0.3 (Linux)
 by: Tavis Ormandy - Wed, 7 Jul 2021 19:25 UTC

On 2021-07-07, Tavis Ormandy wrote:
> It prompts instead. You type 'rd' then press enter, then enter your
> string, then press enter again. It is one additional keypress.
>

I guess it's actually the same number of keypresses, you just press
enter instead of space. Laziness satiated :)

Tavis.

--
_o) $ lynx lock.cmpxchg8b.com
/\\ _o) _o) $ finger taviso@sdf.org
_\_V _( ) _( ) @taviso

Re: How to "sanitise" a string before it is echoed?

<20210707131535.711@kylheku.com>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 563-365-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: How to "sanitise" a string before it is echoed?
Date: Wed, 7 Jul 2021 20:25:40 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 86
Message-ID: <20210707131535.711@kylheku.com>
References: <sc48on$605$1@dont-email.me> <sc4hbu$brd$1@news-1.m-online.net>
<sc4ub9$70i$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 7 Jul 2021 20:25:40 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="548f2a20fc6f64ed83a2926dee93ebad";
logging-data="2401"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/07/5tgZVIJ/d9yig9yWRX7sSm4OQN9FI="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:rbMSJpCUPQW5KuVE5iV5EMNZZb4=
 by: Kaz Kylheku - Wed, 7 Jul 2021 20:25 UTC

On 2021-07-07, Ottavio Caruso <ottavio2006-usenet2012@yahoo.com> wrote:
> On 07/07/2021 16:31, Janis Papanagnou wrote:
>
>>
>> And change your function to
>>
>> echo "$@" | ...
>>
>> to not get other side effects that you not yet notice; try
>>
>> touch sœurA sœurB
>>
>> and call your function to see the undesired effect.
>>
>
> That doesn't seem to work:
>
> $ rd () { echo "$@" | iconv -c -t ascii//TRANSLIT | tr '[:upper:]'
> '[:lower:]'; }
> $ rd Ce CD n'est pas le tien

A function definition cannot repair bad syntax in the funtion's
invoction, which prevents the function from being called.

It's not how functions generally work in programming
languages.

Functions have to be called in order to do anything. Before
they can be called, the calling syntax has to be processed.

The feature you are asking for is changing how the command line is
parsed when the first word is "rd". You want it to be so that
after the "rd" token, all characters until the newline are collected
into a single argument, without recognizing any special characters
such as ' ro ".

The POSIX shell doewsn't have a way to switch to an alternative
command line syntax, and I'm not aware of an extension like that
in any popular shells.

The closest thing is a here-document, which prepares not
argument material for a function/command, but standard input:

rd()
{ cat
}

rd <<'END'
Comme ci, comme ca.
Ceci n'est pas une pipe.
C'est la vie.
END

rd could copy standard input into a variable, and after that you can
prtend that the data had been passed in as an argument:

rd()
{ var=$(cat)
echo "$var"
}

rd <<'END'
Comme ci, comme ca.
Ceci n'est pas une pipe.
C'est la vie.
END

The quotes around 'END' indicate that the here-doc does not
recognize any special characters. It is completely verbatim,
except for recognizing the END terminator.

This lets you write many lines containing quotes and all
sorts of glypsh without worrying about quoting.

If you use <<END, then special characters are recognized and
expansion is performed:

cat <<END
Hello, $USER.
END

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: How to "sanitise" a string before it is echoed?

<sc58ef$ijl$1@news-1.m-online.net>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!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: How to "sanitise" a string before it is echoed?
Date: Thu, 8 Jul 2021 00:05:03 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 36
Message-ID: <sc58ef$ijl$1@news-1.m-online.net>
References: <sc48on$605$1@dont-email.me> <sc4hbu$brd$1@news-1.m-online.net>
<sc4ub9$70i$1@dont-email.me>
NNTP-Posting-Host: 2001:a61:241e:cc01:f959:8494:6a2:cb16
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: news-1.m-online.net 1625695503 19061 2001:a61:241e:cc01:f959:8494:6a2:cb16 (7 Jul 2021 22:05:03 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Wed, 7 Jul 2021 22:05:03 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
In-Reply-To: <sc4ub9$70i$1@dont-email.me>
 by: Janis Papanagnou - Wed, 7 Jul 2021 22:05 UTC

On 07.07.2021 21:12, Ottavio Caruso wrote:
> On 07/07/2021 16:31, Janis Papanagnou wrote:
>
>>
>> And change your function to
>>
>> echo "$@" | ...
>>
>> to not get other side effects that you not yet notice; try
>>
>> touch sœurA sœurB
>>
>> and call your function to see the undesired effect.
>>
>
> That doesn't seem to work:

You missed that my reply has three paragraphs:
1. Why your approach can't work - you need valid shell syntax.
2. What you have to do to make it work - quoting or escaping.
3. What you should anyway do to not run into other issues that
your code has - use "$@" instead of $*.

You did not understand 1., you ignored 2., and 3. will not
magically solve your ignoring of 1.

Janis

>
> $ rd () { echo "$@" | iconv -c -t ascii//TRANSLIT | tr '[:upper:]'
> '[:lower:]'; }
> $ rd Ce CD n'est pas le tien
>>
>
>

Re: Bash: How to "sanitise" a string before it is echoed?

<ikmr26FlujlU1@mid.individual.net>

 copy mid

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

 copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: tav...@gmail.com (Tavis Ormandy)
Newsgroups: comp.unix.shell
Subject: Re: Bash: How to "sanitise" a string before it is echoed?
Date: 7 Jul 2021 23:18:30 GMT
Lines: 27
Message-ID: <ikmr26FlujlU1@mid.individual.net>
References: <sc48on$605$1@dont-email.me> <sc49gn$b84$1@dont-email.me>
<iklqr2FfqhnU1@mid.individual.net> <sc4ugi$70i$2@dont-email.me>
<ikmd1fFjc9mU1@mid.individual.net> <ikmdcfFjc9mU2@mid.individual.net>
X-Trace: individual.net R7Qr9OYCASu2PHqLNF7Q5Qanwt9ltVaHGHVQ93gGAppEh6dq3r
Cancel-Lock: sha1:hD4IugKa4U8i4wzA1xS7ngklg/M=
User-Agent: slrn/1.0.3 (Linux)
 by: Tavis Ormandy - Wed, 7 Jul 2021 23:18 UTC

On 2021-07-07, Tavis Ormandy wrote:
> On 2021-07-07, Tavis Ormandy wrote:
>> It prompts instead. You type 'rd' then press enter, then enter your
>> string, then press enter again. It is one additional keypress.
>>

On behalf of Ottavio:

> [I'm having problems sending to my usenet server. Can you please repost
> this to the newsgroup?]
>
> Thanks. This seems to work:
>
> $ rd () {
> read -ep 'rd> ' l && iconv -c -t ascii//TRANSLIT <<< "$l" | tr
> '[:upper:]' '[:lower:]'; }
> $ rd
> rd> Ce CD n'est pas le tien
> ce cd n'est pas le tien
>
> --
> Ottavio Caruso

--
_o) $ lynx lock.cmpxchg8b.com
/\\ _o) _o) $ finger taviso@sdf.org
_\_V _( ) _( ) @taviso

1
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor