0

Here is an example for my customized program which is executed as:

./TestVariance.exe 2 100 10 .9

I want to write a bash script that runs it several times while changing the second argument each time. After searching some answers on SO, I come up with a script like

#!/bin/bash
let d=2
let s=10
let q=9/10
for i in 'seq 100 100 1000'
do 
    ./TestVariance.exe $d $i $s $q;
done

But it seems that the script only call TestVariance.exe without passing any arguments. I wonder what's wrong with my script?

BTW, is there any advice for vscode extensions on bash script?

3
  • If you want to provide the list of values for i only literally (and not via parameter), you would write for i in {100..1000..100}. Commented Jul 1, 2022 at 9:09
  • let q=9/10 will result in q=0. Based on your initial sample I expect you wanted 0.9. You don't actually need to use 'let' when setting variables, so you could simply use 'q=0.9' or look at tools like bc if you really need to do floating point math. Commented Jul 1, 2022 at 17:16
  • @tjm3772 you are right. But when I put q=0.9, the script just tells me it is a syntax error: invalid arithmetic operator (error token is ".9"). I wonder how to overcome this. Edit: I come to realized that I can just put .9 as plain text, now it runs well! Commented Jul 4, 2022 at 8:02

1 Answer 1

1

It should be

`seq 100 100 1000`

'seq 100 100 1000' is literal.

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

3 Comments

You can replace backticks by bash command substitution: $(seq 100 100 1000). Or you can replace the whole seq subprocess by bash range: {100..1000..100}.
Indeed, I thought it was something more complex...
That's very subtle for me, before I've only used ` in markdown. Thank you very much.

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.