user3642693
user3642693

Reputation: 13

How do I use for loop?

#/bin/bash
file='abc1'
ln -s $file.grd GGG.grd
TTT >file-out.txt

file='abc2'
ln -s $file.grd GGG.grd
TTT >file-out.txt

In this case, how can I modify the code?

Upvotes: 0

Views: 93

Answers (1)

Johan
Johan

Reputation: 20763

Maybe something like this:

#/bin/bash
for n in 1 2 3
do
  file="abc$n"
  ln -s $file.grd GGG.grd
  TTT >file-out.txt
done

If you print the variable $file in the loop then it is easy to see if it becomes abc1..3

#/bin/bash
for n in 1 2 3
do
        file="abc$n"
        echo $file
done

And this prints:

abc1
abc2
abc3

Upvotes: 1

Related Questions