help-bash
[Top][All Lists]
Advanced

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

Re: Splitting variable into two numbers


From: Chris F.A. Johnson
Subject: Re: Splitting variable into two numbers
Date: Tue, 20 Jul 2021 15:37:32 -0400 (EDT)
User-agent: Alpine 2.22 (DEB 394 2020-01-19)

On Tue, 20 Jul 2021, 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.

Input:

var="{5,8}"

Output:

p=5

q=8

var="{5,8}"
IFS=, read p q <<< "${var//[\{\}]/}"

echo "p=$p"
echo "q=$q"

--
   Chris F.A. Johnson                         <http://cfajohnson.com/>
   =========================== Author: ===============================
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
   Pro Bash Programming: Scripting the GNU/Linux shell (2009, Apress)



reply via email to

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