Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
批处理脚本到Shell脚本_Shell_Batch File - Fatal编程技术网

批处理脚本到Shell脚本

批处理脚本到Shell脚本,shell,batch-file,Shell,Batch File,我已经编写了一个小的批处理脚本,它将文件从a文件夹复制并粘贴到另一个文件夹中,延迟时间为10秒。我想把它转换成shell脚本,但没有办法。 请帮帮我。下面是我使用的批处理脚本: @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:

我已经编写了一个小的批处理脚本,它将文件从a文件夹复制并粘贴到另一个文件夹中,延迟时间为10秒。我想把它转换成shell脚本,但没有办法。 请帮帮我。下面是我使用的批处理脚本:

@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 

将sourcedir和targetdir设置为您想要的名称(不是根据您的代码,您总是复制在同一个文件leadboard.txt上,如果您想保留原始名称,只需删除“leadboard.txt”并仅保留“$targetdir”

sourcedir=
targetdir=
对于“$sourcedir”/leadboard*.txt;中的
cp“$a”“$targetdir”/leadboard.txt
睡眠10
完成

注意:如果您要复制的文件名中有空格,则此解决方案不起作用

只要您继续引用
$a
$sourcedir
$targetdir
,则此解决方案对于带有空格的文件名应该可以正常工作。在扩展路径名之前会进行分词。
sourcedir=<SOURCEDIR>
targetdir=<TARGETDIR>

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