How can I convert this .sh script to a windows executable (.bat)?

I created a shell script long back to create a nested directory structure and I now want to use it on my windows machine. Is there an easy way to convert this scripts? Or some quick tips that I should use?

#!/bin/sh
echo "Enter name of csv file"
read name
echo "Enter the PREFIX for the directory"
read prefix
c=$(echo $prefix | awk -F"/" '{print $NF}')
a=`cat ./$name`
for b in $a
do
mydir=$(echo $b | tr -d '\r' | sed -e 's/,*$//g'| sed -e 's/,/\//g')
mydir2=$(echo $mydir | sed -e 's/\//\/'$c'/g')
mydir1=$prefix$mydir2
mkdir -p $mydir1
echo "Created : `pwd`/$mydir1"
done

The following might serve as a starting point: https://daniel-sc.github.io/bash-shell-to-bat-converter/

Disclaimer: I created this tool. I know it's far from complete. PRs/Help always welcome :)


There's not really a magical way to convert scripts, except to re-write said scripts manually. That might not always be 100% possible, due to the limitations in the Windows Command Prompt.

However, instead of converting the script, perhaps you could get a windows program that can execute it. If you have Windows 10, you can simply use the new Linux subsystem. There are a million webpages explaining how to do this, so you should be able to find information via a simple websearch.

If you're not running Windows 10, I would recommend a Windows-compatible versions of the Borne Again SHell, and Un*x untilities (specifically awk, cat, sed, and tr, since those are what the above script seems to require). MinGW has a good version of both, which you can get (bundled together) from here. Run the setup program, and you'll see a window called "MinGW Installation Manager", which will have various packages you can install. "msys-base" should be the only one you need (unless you plan on compiling source code) so put a check mark in the box next to it. Then, go to the "Installation" menu, and select "Apply Changes", and in the window that appears, click "Apply". Assuming you installed MinGW in the default directory (C:\MinGW), bash should be located in C:\MinGW\msys\1.0\bin\bash.exe. You can use this exe file to run your shell scripts.