[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 20:20:29 +0200 (CEST) |
The multi-input is always enclosed within braces with no whitespaces.
Thus "{5,8}", "{13,21}"
In general input is "{p,q}" with no whitespaces
Nothing more than that.
Then p=5; q=8 and p=13; q=21
From: Greg Wooledge <greg@wooledge.org>
To: help-bash@gnu.org
Subject: Re: Splitting variable into two numbers
Date: 20/07/2021 19:05:01 Europe/Paris
On Tue, Jul 20, 2021 at 06:15:32PM +0200, lisa-asket@perso.be wrote:
> I would like to split a variable containing two numbers delimited by a comma
>
> and transfer the two numbers into two variables p and q.
p=${input%,*} q=${input#*,}
> Input:
>
> var="{5,8}"
STOP!
All of a sudden, this is an X-Y problem. You don't have "two numbers
delimited by a comma". You have something else entirely. There are
curly braces now. I wonder what else is in there.
Is it really JSON?
What's the *actual* goal here? Where does this input come from, what
does it *really* look like (before any mangling you've already done
on the X-Y path), and what are you trying to do with it?
- Splitting variable into two numbers, lisa-asket, 2021/07/20
- Re: Splitting variable into two numbers, Leonid Isaev (ifax), 2021/07/20
- Re: Splitting variable into two numbers, Greg Wooledge, 2021/07/20
- Splitting variable into two numbers,
lisa-asket <=
- Re: Splitting variable into two numbers, Greg Wooledge, 2021/07/20
- Splitting variable into two numbers, lisa-asket, 2021/07/20
- Re: Splitting variable into two numbers, Greg Wooledge, 2021/07/20
- Splitting variable into two numbers, lisa-asket, 2021/07/20
- Re: Splitting variable into two numbers, Greg Wooledge, 2021/07/20
- Re: Splitting variable into two numbers, ikhxcsz7y xmbott, 2021/07/21
Re: Splitting variable into two numbers, Chris F.A. Johnson, 2021/07/20