[Top][All Lists]

[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 <>
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, 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}"


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?

reply via email to

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