0

while running this code , I get this error:

syntax error near unexpected token (' touch FILE$i FILE($i+1);'

what is wrong ?

#!/bin/bash

  for ((i=1; i<=99; i++ ));
    do        
    touch FILE$i FILE($i+1);
    ln -s FILE$i FILE($i+1);
       
     done


1
  • Off-topic: When you are going to ln -s FILE 1 FILE2, you do not need to touch FILE2 first. Your code is trying to make a chain of symbolic links. Are you sure you want that, or do want FILE2,..,FILE99 all linked to FILE1. In that case you might want touch FILE1; for ((i=2;i<=99;i++));do ln -s FILE$i; done. Commented Nov 1, 2020 at 13:17

1 Answer 1

1

To do arithmetic, use the $((...)) syntax:

    touch FILE$i FILE$(($i+1))

See https://www.gnu.org/software/bash/manual/bash.html#Arithmetic-Expansion

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.