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...? Nov 23 at 15:56
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. Nov 23 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.