0

I'm struggling with this script, I have tried different thing but I can't get it to work.

I tried with if ,doesn't work, I tried with nested while also without success. I don't know what to do any more...

If the value imax has reached 10 i want it to start over with 1

this is the code:

folder="f"
ps=20000
name="test"
i=1
imax=1

while [ $i -le 20 ]
    do
        cd
        cd "$folder$((i))"
        sed -i 1s/.*/$name$((imax))/ file.txt
        sed -i 2s/.*/$ps/ file.txt
        (( i++ ))
        (( imax++ ))
    done

Thank you

1 Answer 1

2

Something like this works:

i=1
imax=1
while [ $i -le 20 ]   
   do
       echo $i $imax
       (( i++ ))
       (( imax++ ))
       if [ $imax -eq 10 ]; then  imax=1; fi
   done
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.