0

How can I echo questions to the Terminal, and pass the answers to the same script?

The steps would be:

  1. A script that output the questions - one question after the other where I can add the answers after the :.

    Example:

    Number 1: 2

    Number 2: 4

    Number 3: 6

  2. A way to pass the arguments given in step 1 to the script and calculate the sum.

The final output would be: 12.

1
  • You might want to look at expect for how to pass arguments, or have a script that can take the values in other ways like command line arguments Commented May 7, 2018 at 15:11

1 Answer 1

2

Is this what you had in mind?

#!/bin/bash
read -p "Number 1: " N1
read -p "Number 2: " N2
read -p "Number 3: " N3
echo "Sum: $((N1 + N2 + N3))"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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