0

I am trying to call an executable with two arguments within a nested for loop (I'm also writing in bash scripting). I thought I was doing it correctly, but all my values show up in the text file as 0. i.e. tilt 0 angle 0 even though the values are obviously not. My code is as such:

for (( i=0; i <=3; i++)); do
    for (( j=0; j <= 3; j++ )); do
        ./solar_sim 'i' 'j' >> solarResults.txt
        echo -n "$i"
    done
    echo " "
done

`

The solar_sim was provided to us and output a line like this, which I write to a file:

10000 hours, angle: 0.00 degrees, temperature: 0.00 degrees C, total power: 119871.00 Watts Am I doing something wrong in the calling of solar_sim? I also tried using $i and $j

2 Answers 2

2

Your mistake is this line :

./solar_sim 'i' 'j' >> solarResults.txt

should be rewritten like this :

./solar_sim "$i" "$j" >> solarResults.txt

Also, echo is sufficient alone, no need echo " " to print a newline

Sign up to request clarification or add additional context in comments.

4 Comments

Oops! Forgot the double quotes. Thanks so much!
Not only the double quotes but the sigils
I'm pretty new to bash scripting, so I was experimenting. Got the sigils in. Thanks. Will upvote when able
Yes, I know. I had to wait the required amount of time. No need to be rushed!
-1

It looks like you forgot the "$" to de-reference the i and j variables

./solar_sim "$i" "$j" >> solarResults.txt

2 Comments

Where's there's references ? This is just some basic variables... And in single quotes, variables are not interpolated !
Excuse me if my terminology is not perfect. It sure looked to me like the script was intending to reference the variables value.

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.