Run bat file in linux

Can I run Windows .bat files in Ubuntu?

I want to run a .bat file in ubuntu, but it just opens the text editor. Here’s the code of the .bat file(you can play it):

@echo off set /a guessnum=0 set /a answer=%RANDOM% echo Welcome to the Guessing Game! echo. echo Try and Guess my Number! echo. echo. goto guess :guess set /p guess= set /a guessnum=%guessnum% +1 if %guess% GTR %answer% ECHO Lower! if %guess% LSS %answer% ECHO Higher! if %guess% EQU %answer% GOTO EQUAL goto goto guess :equal echo Congratulations, You guessed right. echo. echo It took you %guessnum% guesses. echo. pause 

The file is seen as being text; hence opening in the text editor. Files are marked as executable via chmod (or GUI tools) which you didn’t do, but the file must have an interpreter installed that knows how to execute it (usually the type of file can be determined, but the shebang on first line is always a safety item to ensure it’s interpreted correctly — your file has none). You’ll need to add software that knows how to interpret it, as it’s not BASH script, not perl, not python, not CSH etc.

This code is erroneous, so there is no output from this batch file. The statement goto top can’t be executed because there is no label named :top in this batch file. Debugging batch files is off topic at Ask Ubuntu. Try asking for help at a Windows site or Stack Overflow.

2 Answers 2

By the looks of it, most of it (the parts using the “echo” command) should work, but not the batch-specific parts (e.g. “goto”). But you should be able to convert it to a shell script and then it might work, or you may be able to emulate it within Ubuntu.

Читайте также:  Arch linux driver manager

Edit: I’ve converted it, it appears to be incomplete. It appears to have converted the «if» parts, but not anything else. Let me know if it works (I highly doubt it), I’ll also try it personally. I hope it helps. (Moderators, please update this answer with a fully converted script if possible.)

export -a guessnum=0 export -a answer=$ echo Welcome to the Guessing Game! echo "" echo Try and Guess my Number! echo "" echo "" export -p guess= export -a guessnum=$ +1 if $ echo Lower! if $ echo Higher! if $ echo EQUAL goto top :equal echo Congratulations, You guessed right. echo "" echo It took you $ guesses. echo "" pause 

Источник

How do I create a batch file and run it? [duplicate]

Your question is more likely to receive useful answers if it contains some specifics. Such as what type of data is to be processed, including realistic examples of input and output.

@SergiyKolodyazhnyy The duplicate nominee is closed as too broad. As such the close vote on this one should be «too broad» as well. That said it seems like a reasonable question to me as I was once in the dark myself 🙂

@WinEunuuchs2Unix It is closed but does have an accepted answer, which will give OP what they want, or at least a starting point.

@EliahKagan If a mod agrees perhaps he can reopen that one and then merge the answers from here to there?

@WinEunuuchs2Unix That question, which this received close votes to be duped to, was actually reopened a few hours ago, then closed again as duplicate of that highly voted question. Both of them are listed as «originals» in the duplicate banner here (i.e., this question is duped to both of them). So if answers are to be merged, they’d probably be put there. Do you think that would be useful?

3 Answers 3

To create one use the .sh extension but it doesn’t really matter but it helps future users to quickly determine which file type it is. The bat name is mostly used on Windows but in Linux file name extensions do not really matter. Meaning I can call my file say run.de and it would still run in bash file but I believe it’s a good practice to name them with the .sh file extension.

For the editor, part uses any that is best for you between nano vim gedit emacs , but I believe gedit would be nice to start with.

Читайте также:  Linux get file content

Источник

Do batch files work on linux?

Unfortunately, many of the answers such people receive state that batch scripts cannot run on Linux. However, Linux users can indeed run batch files. Also, Windows batch files can be run on Windows like a native shell script.

What is batch file in Linux?

A batch file is a script file in DOS, OS/2 and Microsoft Windows. It consists of a series of commands to be executed by the command-line interpreter, stored in a plain text file. . Unix-like operating systems, such as Linux, have a similar, but more flexible, type of file called a shell script.

Can you run BAT files on Ubuntu?

bat file, it will open in gedit>Tools>External Tools>Run command>in the popped up box type ‘wineconsole cmd‘ (without inverted commas)>OK. 5. A Wine console terminal will pop up, in it type ‘start yourfilename. bat’ and hit enter.

Does cmd work in Linux?

Most of us think that Linux has terminal and we can use a command-line interface only in Linux but it is just a myth. There is a PowerShell and a command prompt in windows as well where we may execute the commands easily. But Windows and Linux have commands with the same name as well.

What files run on Linux?

A RUN file is an executable file typically used to install Linux programs. It contains program data and installation instructions. RUN files are often used to distribute device drivers and software among Linux users. You can execute RUN files in the Ubuntu terminal.

How to run .bat(Batch) Files on Linux (Ubuntu)

45 related questions found

Why is permission denied Linux?

While using Linux, you may encounter the error, “permission denied”. This error occurs when the user does not have the privileges to make edits to a file. . Other users, however, may not be allowed to make such edits. Remember that only root or users with Sudo privileges can change permissions for files and folders.

Can you run EXE files on Linux?

1 Answer. This is totally normal. .exe files are Windows executables, and are not meant to be executed natively by any Linux system. However, there’s a program called Wine which allows you to run .exe files by translating Windows API calls to calls your Linux kernel can understand.

Is Windows a Linux terminal?

Windows Terminal is a modern terminal application for users of command-line tools and shells like Command Prompt, PowerShell, and Windows Subsystem for Linux (WSL).

Читайте также:  Линукс запустить файл run

Is Windows Terminal like Linux?

The Windows Terminal is a modern, fast, efficient, powerful and productive terminal application. It combines many command-line tools and shells such as Command Prompt, PowerShell and WSL (Windows Subsystem for Linux).

Is CMD a terminal?

So, cmd.exe is not a terminal emulator because it is a Windows application running on a Windows machine. There is no need to emulate anything. It is a shell, depending on your definition of what a shell is.

What are .sh files in Linux?

An SH file is a script programmed for bash, a type of Unix shell (Bourne-Again SHell). It contains instructions written in the Bash language and can be executed by typing text commands within the shell’s command-line interface.

What is the Linux equivalent of a batch file?

Batch file equivalent in linux is shell script (. sh). You can use gedit, vim or any other text editor available to create one.

How do I run a .sh file in Linux?

  1. Select the file using mouse.
  2. Right-click on the file.
  3. Choose Properties:
  4. Click Permissions tab.
  5. Select Allow executing file as a program:
  6. Now click the file name and you will be prompted. Select “Run in the terminal” and it will get executed in the terminal.

Источник

Executing .bat file

I have a setup.bat file which install some applications and i want to execute it. This is content of .bat file :

@echo off cls Rip_7z.exe x Rip0.7z cls del Rip0.7z cls Rip_7z.exe x Rip1.7z cls del Rip1.7z 

I think the Rip_7z.exe file extracts the Rip0.7z and Rip1.7z files and builds the app. How can I do this in the Ubuntu 11.04 Terminal?

4 Answers 4

You can run DOS batch file through wineconsole :

$ cat ~/.wine/drive_c/file.bat @echo off echo Working pause $ wineconsole 'C:\file.bat' 

You get a new windows similar to this

enter image description here

Also, you can enter an interactive DOS prompt with

enter image description here

You have to run it through cmd eg.: wine cmd /c setup.bat

Firstly, Wine won’t touch batch files.

Why do you have to do it in a terminal? Just open the directory with naultilus, right click the .7z files and extract. But if you want to do it the hard way, the appriximate conversion of that script is:

#!/bin/bash 7za x RipForGames.7z # might want e instead of x #rm RipForGames.7z # commented out in case you want to keep them. 

A protip for next time: Try not to announce you’re downloading pirated material, in a public forum. It might come back to bite you in the arse one day.

Источник

Оцените статью
Adblock
detector