1

I'm having some problems with the following code:

echo XX.txt 4 | script

The script should write the 4th line of XX.txt, but I'm having trouble getting both echoed arguments into variables in the script. I have to use echo because it's a school exercise. :)

How can I get XX.txt and 4 as seperate variables in my script? I've tried using read, but it puts both arguments in only 1 variable.

Hope you can help me

1 Answer 1

2

read should work. You have to specify both variables to it, though:

echo XX.txt 4 | { read file num
                  echo File: $file
                  echo Num: $num
                }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot! I didn't know I could get multiple variables with read! Thanks !

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.