views:

64

answers:

4

hi,

I'm no linux user (yes, I'm sorry!) and a friend of mine asked me to port his shell script for linux into a batch for windows, because he wants to do the same task there to.

I haven't worked with shell-scrips before and my batch skills are, hmmm, almost not existing, but I would like to try that.

So I would like to ask if there are all shell functionalities in batch.

thanks in advance,

Andreas

A: 

Batch commands are .BAT which are executed by the Windows CMD process.

The Linux shell scripts are a world and a breed apart from BATCH..depending on the start of the Linux script #!/bin/xxxxx where xxxxx could be bash, csh, korn, zsh, ash....

You may be better off to look into PowerShell (Monad) under Windows to achieve a similar thing. Another link to PowerShell here. Have a look at PowerShell Scripting Guy site.

Using Powershell to make an equivalent of the Linux shell script - you may pull this one off... The alternative notion and concept is to use AutoIt scripting functionality which is BASIC like....

The only thing to bear in mind is this, a lot of the shell script functionality may be referencing other linux commands that are not present on Windows... depending on the script's complexity there may be substitutions for a linux command (if any) to a Windows command.

It might help to post the script in it's entirety...

tommieb75
A: 

Batch and shell(bash etc) scripts are not the same. The only best way to do this is to do learn about batch/vbscript and shell , and then convert them manually. Or you can install cygwin or GNU win32. These will help you run your shell scripts on windows, but you might have to make some changes, depending on what is written.

ghostdog74
A: 

In short, no. While conceptually writing shell scripts and batch files are similar, the syntax and commands are totally different. For example, a common command in bash cat is type in windows, etc. Generally, however, the DOS commands should have equivalents in Linux.

Your script won't work in Linux. If your friend uses bash (chances are he does), than you can look at some tutorials and documentation to "translate" his script into a Windows one, much in the same way one would translate a piece of code written in C to Python, a totally different language with different syntax but many common features.

Here's a great tutorial I used to learn sh, the language that bash shell scripts are written in. It's a bit fast-paced, but if you can write scripts in batch most of it should make sense to you.

If you want to find out what a command is in bash, the documentation and reference manual can be found here.

If you need specific help with something in the script, post it and I'm sure someone will tell you what you need to do.

Rafe Kettler
A: 

The answer to the actual question, is no, not all shell-script commands work in Windows' Batch files.

But, that's not to say the script could not be ported to Windows. There are many languages that could be used to get the desired results. The first step is to define the output needed, and the types of operations that are being performed, then you can figure out which language is best suited for the task.

If you want to keep maintaining two versions of the program, then you could use C, C++, AutoIt, C#, VB.Net, etc. to write a Windows only version.

OR you could look at porting the existing shell script that is already written in Linux to a language such as Ruby, Python or Perl -- and then it would be more likely to run on both Linux and Windows with much fewer changes.

JohnForDummies