help-bash
[Top][All Lists]
Advanced

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

Splitting variable into two numbers


From: lisa-asket
Subject: Splitting variable into two numbers
Date: Tue, 20 Jul 2021 22:07:28 +0200 (CEST)

From: Greg Wooledge <greg@wooledge.org>
To: help-bash@gnu.org
Subject: Re: Splitting variable into two numbers
Date: 20/07/2021 20:50:30 Europe/Paris

On Tue, Jul 20, 2021 at 08:38:46PM +0200, lisa-asket@perso.be wrote:
>> I could get somewhere with the following
>> echo "{5,8}" | awk -F"[{}]" '{print $2}'

>I categorically reject any solution that forks a whole new program just
>to do some trivial string parsing. It's nearly as bad as the old Bourne
>shell days when people had to fork an expr(1) program just to add 1 to
>a counter variable.

>The solution I gave does not fork any new processes (neither subshells
>nor whole new programs), nor does it involve creating temporary files,
>setting up pipes, or any of the other expensive operations that parsing
>input strings in bash often requires.

>This is possible because the specification for the input format is so
>strict. There are always exactly two numbers, with known punctuation
>around them. So, POSIX parameter expansions are quite sufficient.

>> Am just searching through a list of files between lines p and q.

>That's what you're using the outputs for. But where does the *input*
>come from? Why is it in this weird format with curly braces?



Just a user argument to a function.  What is a compound way to pass 

multiple values that are not considered weird ? Have no problem about

changing away from curly braces.  At least the user would not be required

to escape them on quote the value.



>Obviously you're free to ignore the question, because I've already
>answered your literal question. I just can't help feeling that you're
>asking the wrong question, and if you look at the bigger picture, you
>could avoid some of the work you've already done and simplify a whole
>lot more of your life.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]