0

I have another file that has 2 numerical values...

22

35

I want to read those values and assign each to a variable.

There will only ever be two values, so a loop shouldn't be necessary.

I found ways to get the value line by line, but I'm unsure how to save those values to a variable that I can use in my main script.

3 Answers 3

3

Another way to read two lines in succession is:

{ read var1 ; read var2 ; } <data
Sign up to request clarification or add additional context in comments.

Comments

0

You can use:

read a b < <(egrep -o '[0-9]+' file|tr '\n' ' ')

Comments

0

With bash 4, you can read the lines into an array

mapfile -t numbers < file
echo ${numbers[0]} ${numbers[1]}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.