Vaibhav
Vaibhav

Reputation: 353

Batch Script to Shell Script

I have written a small batch script which copies files from the a folder and paste in other folder with delay of 10 seconds. I want to convert it to shell script, but not getting the way to do that. Please help me. The below is the batch script that i use:

@echo off & setLocal EnableDELAYedExpansion

pushd "C:\Users\abc\Desktop\Test"
for /f "tokens=*" %%a in ('dir /b/a-d "leaderboard*.txt"') do (
copy "%%a" "C:\Users\abc\Desktop\Test\final\leaderboard.txt"
timeout 10
) 
popd 

Upvotes: 0

Views: 165

Answers (1)

Teudimundo
Teudimundo

Reputation: 2670

Set the sourcedir and targetdir to the one you want (not according to your code you always copy on the same file leaderboard.txt, if you want to keep the original name just remove "leaderboard.txt" and keep only "$targetdir"

sourcedir=<SOURCEDIR>
targetdir=<TARGETDIR>

for a in "$sourcedir"/leaderboard*.txt; do
    cp "$a" "$targetdir"/leaderboard.txt
    sleep 10
done

NB: This solution does not work if you have spaces in the name of the files you want to copy

Upvotes: 1

Related Questions