0

I want to convert a .bat file to a .sh file.

The .bat file looks like this:

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

pause

This is how I think how the .sh should look like, however I am not sure whether it is right:

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

sleep

It returns 'errorcode 1' along with the following errors:

abc.exe: command not found

sleep: missing operand

Wienn
  • 1
  • 1
  • 4
    Try it and see what happens ? If it doesn't work then come back here with the error/the current behavior ? – xoxel May 21 '18 at 13:39
  • 3
    Possible duplicate of [Get program execution time in the shell](https://stackoverflow.com/questions/385408/get-program-execution-time-in-the-shell) –  May 21 '18 at 16:31

2 Answers2

0

It wont work as it is passing something to abc.exe which is executable file and your .sh files will run in unix environment.

You have to make use of third party application WINE which will run .exe on linux environment.

0

It is very unusual in Unix to have an .exe extension. Most unix commands have no extension at all. So likely whatever was abc.exe should just be abc, provided that the executable does exist.

Typically Unix also does not include the current directory in the PATH (DOS does). So if abc is in the current directory, you'll need to call it ./abc.

There are a number of other errors here. What you likely mean is closer to this:

title=`pwd`   # You never seem to use this, though?
start=`date`
./abc xxx.run
echo $start
date
Rob Napier
  • 250,948
  • 34
  • 393
  • 528
  • Isn't `%cd%` closer to `"$cd"` and `%time%` closer to `"$time"` though? – tripleee May 21 '18 at 17:01
  • No; `%cd%` returns the current working directory in BAT. `%time%` returns the current time. The near-equivalents in bash are `pwd` and `date` (the format will be a little different, but it's a similar result). In this bash script, `$cd` would return nothing, since that variable isn't set. – Rob Napier May 21 '18 at 21:21