I've made a file with a Simple Linear Regression code that calculates the average of x and y values, and their standard deviations. Now, instead of inserting values myself (user input), I want to make a different file with values already stored in it and kind of "feed" them into my Linear Regression code. How do I go about doing so? (Bear in mind, I have Windows 10 so please do provide me with code that's compatible with my OS)

P.S. I'm very new to the Bash/Ubuntu environment so I'm not aware of almost everything used in the terminal.

  • It depends on how your script expects to obtain values - as arguments (positional parameters)? streamed via standard input? prompted for and read one-by-one via standard input? It would be easier to answer if you included at least the relevant portion of the script in your question – steeldriver Feb 6 at 23:11


1    2
3    4
5    6



# Import values form a file into an array using redirect.
echo "count: ${#array[@]}, data: ${array[@]}"

# We increase the counter i by the number of columns.
for ((i=0; i<${#array[@]}; i+=2)); do
     echo "X=${array[$i]}, Y=${array[(i+1)]}"
  1. Create your variable file by this other software so that it looks like this:

    $ cat /tmp/foo.var   
  2. From your bash script then source your variable file /tmp/test.txt like this:

    source /tmp/foo.var   
    echo "$foo1"

Adapt the paths accordingly. Especially when using windows.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.