0

I made a script so I can easily execute multiple programs in different terminals by just writing

./script.sh (numberofprogramstype1) (numberofprogramstype2)

The problem is it only executes one of each type, even though I am looping it based on the arguments given. Here is my code:

gcc program1.c -lpthread

for i in {1..$1}
do
       gnome-terminal -e ./a.out
done

gcc program2.c -lpthread

for i in {1..$2}
do
        gnome-terminal -e ./a.out
done

Why is this happening and how can I solve it?

1 Answer 1

1

Brace expansion happens before parameter expansion; you can only use hard-coded numbers in them. Use a C-style for loop instead.

# {1..$1}
for ((i=1;i<=$1;i++)); do
   ...
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.