Batch file 将.BAT转换为.SH

Batch file 将.BAT转换为.SH,batch-file,unix,sh,Batch File,Unix,Sh,我想将.bat文件转换为.sh文件 .bat文件如下所示: @echo off title=%cd% set start=%time% abc.exe xxx.run @echo %start% @echo %time% pause 我认为.sh应该是这样的,但我不确定它是否正确: #!/bin/sh set +v title=$cd$ set start=$date$ abc.exe xxx.run set +v echo $start$ set +v echo $time$ sleep

我想将.bat文件转换为.sh文件

.bat文件如下所示:

@echo off
title=%cd%
set start=%time%
abc.exe xxx.run
@echo %start%
@echo %time%

pause
我认为.sh应该是这样的,但我不确定它是否正确:

#!/bin/sh
set +v
title=$cd$
set start=$date$
abc.exe xxx.run
set +v echo $start$
set +v echo $time$

sleep
它返回“errorcode 1”以及以下错误:

abc.exe:找不到命令


睡眠:缺少操作数

它无法工作,因为它正在向abc.exe(可执行文件)传递某些内容,而您的.sh文件将在unix环境中运行


您必须使用第三方应用程序WINE,该应用程序将在linux环境下运行.exe。

在Unix中使用
.exe
扩展是非常罕见的。大多数unix命令根本没有扩展名。因此,只要可执行文件确实存在,那么无论是什么
abc.exe
都应该是
abc

通常Unix也不在路径中包含当前目录(DOS会)。因此,如果
abc
位于当前目录中,则需要将其命名为
/abc

这里还有许多其他错误。您可能的意思更接近于此:

title=`pwd`   # You never seem to use this, though?
start=`date`
./abc xxx.run
echo $start
date

试试看会发生什么?如果它不起作用,那么带着错误/当前行为返回这里?可能的重复不是
%cd%
更接近
“$cd”
,而是
%time%
更接近
“$time”
,但是?不是<代码>%cd%返回BAT中的当前工作目录<代码>%time%返回当前时间。bash中的近似等价物是
pwd
date
(格式略有不同,但结果类似)。在这个bash脚本中,
$cd
将不返回任何内容,因为没有设置该变量。