1

I have a script that copies a file from one directory to another indefinitely (until cancelled) as a test. I am trying to write a bash script that takes file.xml, copies it to a directory, but increments the filename each time, i.e. file1.xml, file2.xml, etc. I've been coming up short thus far with the solutions I've found on SE. Any help would be appreciated.

1
  • What are you testing with that, the page cache...? Commented Nov 23, 2021 at 15:56

1 Answer 1

1
#! /bin/bash

source_path='/path/to/file.xml'
dest_dir_path='/path/to/dest'

i=1
while true; do
    cp "$source_path" "${/path/to/dest}/file${i}.xml"
    ((i++))
done
1
  • Appreciate it. That is way better than the nightmare I tried. Commented Nov 23, 2021 at 18:08

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.